473,396 Members | 2,038 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Good brain teaser (real life problem)


Let's say I have this class.

public class oompa_loompa: halfling
{
public var automobile;
}

public first_oompa_loompa oompa_loompa = new oompa_loompa();

Nov 17 '05 #1
5 1941
Apart from the fact that you got your declaration backward (I think
that you meant to say:

public oompa_loompa first_oompa_loompa = new oompa_loompa();

), if I may take the liberty of rephrasing your question:

"Can a base class method change the value of one of the fields of its
derived class?"

So long as the base class has a reference to an instance of the derived
class, I don't see why not. However, from the base class's point of
view, the derived class object is just another object instance, like
any other object in the system. Unless you use Reflection, that is.

So, you could use Reflection to ask the question, "Do I have a field
called automobile?" and alter that field if you did.

Or, you could pass a reference to the derived class to its own base
class method and have the base class treat the derived class argument
like any other object (and so be able to manipulate any public fields,
properties, etc.)

However, both of these would be gross abuses of inheritance. Why do you
want to do something like this?

Nov 17 '05 #2
This is using the deprecated oompa_loompa API. oompa_loompa.find was
superceeded in the IOompaLoompa interface from the October CTP for CF2005
project codenamed "Lindt"

Try implementing IOompaLoompa.DoompetyDoo(string _message);

If this doesn't resolve your problem a good workaround will be to replace
your everlasting gum and turn the sound on the teevee right down.

HTH....

--
Bob Powell [MVP]
Visual C#, System.Drawing

Ramuseco Limited .NET consulting
http://www.ramuseco.com

Find great Windows Forms articles in Windows Forms Tips and Tricks
http://www.bobpowell.net/tipstricks.htm

Answer those GDI+ questions with the GDI+ FAQ
http://www.bobpowell.net/faqmain.htm

All new articles provide code in C# and VB.NET.
Subscribe to the RSS feeds provided and never miss a new article.

<ar*******@hotmail.com> wrote in message
news:11*********************@g14g2000cwa.googlegro ups.com...

Let's say I have this class.

public class oompa_loompa: halfling
{
public var automobile;
}

public first_oompa_loompa oompa_loompa = new oompa_loompa();

.
.
.

first_oompa_loompa.find()
Is it possible to call first_oompa_loompa.find() and have the halfling
class, instantiate an automobile object and set first_oompa_loompa.var
to reference that new instance?

I have thought of a couple of alternatives but there ought to be an
easier way.

Arturo Hernandez

All the variable names on this posting have been changed to protect the
identity of the real variables.

PS: If anyone says MVP's don't have a sense of humour I'll be round there to
sort you out.
Nov 17 '05 #3

Bob Powell [MVP] wrote:
This is using the deprecated oompa_loompa API. oompa_loompa.find was
superceeded in the IOompaLoompa interface from the October CTP for CF2005
project codenamed "Lindt"

Try implementing IOompaLoompa.DoompetyDoo(string _message);

If this doesn't resolve your problem a good workaround will be to replace
your everlasting gum and turn the sound on the teevee right down.


You know, it gets very frustrating when so-called MVP's give invalid
information. As all of us *true* geeks know... they are everlasting
GOBSTOPPERS. Geez.

:)

Matt

Nov 17 '05 #4
Yea it threw me for a loompa all right %-)

<%= Clinton Gallagher
METROmilwaukee (sm) "A Regional Information Service"
NET csgallagher AT metromilwaukee.com
URL http://metromilwaukee.com/
URL http://clintongallagher.metromilwaukee.com/
"Matt" <ma********@sprynet.com> wrote in message
news:11**********************@g44g2000cwa.googlegr oups.com...

Bob Powell [MVP] wrote:
This is using the deprecated oompa_loompa API. oompa_loompa.find was
superceeded in the IOompaLoompa interface from the October CTP for CF2005
project codenamed "Lindt"

Try implementing IOompaLoompa.DoompetyDoo(string _message);

If this doesn't resolve your problem a good workaround will be to replace
your everlasting gum and turn the sound on the teevee right down.


You know, it gets very frustrating when so-called MVP's give invalid
information. As all of us *true* geeks know... they are everlasting
GOBSTOPPERS. Geez.

:)

Matt

Nov 17 '05 #5
Hi Arturo,
Let's say I have this class.

public class oompa_loompa: halfling
{
public var automobile;
}

public oompa_loompa first_oompa_loompa = new oompa_loompa(); // Fixed by
nick .
.

first_oompa_loompa.find()
Is it possible to call first_oompa_loompa.find() and have the halfling
class, instantiate an automobile object and set first_oompa_loompa.var
to reference that new instance?


Use a constructor:

public class oompa_loompa: halfling
{
public var automobile;
public oompa_loompa()
{
automobile = new var();
}
}
Now, when you create the oompa_loompa object, the constructor will create
the automobile object, and 'first_oompa_loompa' will behave just like a
halfling with an extra public property of 'automobile'. All this before you
even call 'find'.

On the other hand, if 'find' is supposed to find the automobile object, then
you will want to take a look at the Template Method pattern.

public interface ITransportation
{
public void LoadFromDatabase();
}

public class halfling
{
public abstract ITransportation ReturnTransport();
public void find()
{
ITransportation txp = this.ReturnTransport();
txp.LoadFromDatabase();
// do some interesting things here...
}
}

public class oompa_loompa : halfling
{
public ITransportation automobile;
public oompa_looma() // constructor
{
automobile = new PersonalTransport(4,4); // create a new object of
type PersonalTransport with four doors and four wheels.
}
public ITransportation ReturnTransport()
{
return automobile;
}
}

Use http://search.msn.com to find out more about the "template method design
pattern"

--
--- Nick Malik [Microsoft]
MCSD, CFPS, Certified Scrummaster
http://blogs.msdn.com/nickmalik

Disclaimer: Opinions expressed in this forum are my own, and not
representative of my employer.
I do not answer questions on behalf of my employer. I'm just a
programmer helping programmers.
--
Nov 17 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: brendan | last post by:
here's a brain teaser for someone with more skills or at least more lateral thinking capability than me - done my nut over this one... have written a list manager in PHP which a) posts out new...
13
by: James Stroud | last post by:
Hello, I have strings represented as a combination of an alphabet (AGCT) and a an operator "/", that signifies degeneracy. I want to split these strings into lists of lists, where the...
3
by: Gérard Talbot | last post by:
Hello all, When webfonts are used for purely cosmetic/ornemental reasons and on a large scale, I don't agree. When webfonts are used because Unicode support among browsers for a particular...
13
by: KV | last post by:
I'm new to OO Design, and I'm fixing to start writing my very first C# program. Given the complexity of OO programming, I would like to run something by this group and get general input. My...
15
by: Chung Leong | last post by:
Here's a little brain teaser distilled from a bug that took me a rather long time to figure out. The two functions in the example below behave differently. The difference is easy to spot, of...
3
by: datagal | last post by:
I have a requirement (motivated by a SOX thing) that is just giving me fits. I know it should be easy and I'm probably overthinking it, but I just can seem to find the best way to get where I need...
13
by: sd00 | last post by:
Hi all, can someone give me some coding help with a problem that *should* be really simple, yet I'm struggling with. I need the difference between 2 times (Target / Actual) However, these times...
2
RedSon
by: RedSon | last post by:
Given a directed graph of k-nodes such that the last node creates a cycle with any other node determine which node the last node's edge points to using the minimum amount of resources and without...
206
by: WaterWalk | last post by:
I've just read an article "Building Robust System" by Gerald Jay Sussman. The article is here: http://swiss.csail.mit.edu/classes/symbolic/spring07/readings/robust-systems.pdf In it there is a...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.