Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Class instances with unique implamentation

Status
Not open for further replies.

Yesuslave

Programmer
Sep 24, 2003
28
US
Hi all,

OK, I'm trying to find out whether or not this is possible. What I want to do is have a general class where a basic list of methods are predefined, let's say "Car." Car will have the "Start" method, the "Accelerate" method, and the "Turn lights on" method.

Now, I want all instances of Car to have the same basic methods, however, when I instantiate a particular instance of car I want to override the "Turn lights on" method with a more complicated method that checks other factors.

Now, if I was going to make a whole class of these cars that have a different way of checking the "Turn lights on" method, I would make a class and inherit from Car. However, I am only going to make one with that particular difference. I will be making a multitude of these "almost-cars" that share, for the most part, the same methods and implamentation. However, none of the methods will always be the same, and all of them could change slightly instance to instance.

Is there a way, at instantiation, to override the standard method in the class? Something like:

Dim SpyCar as Car
SpyCar = New Car
Override SpyCar.TurnLightsOn()


I know that probably looks nothing like the actual syntax would (if there even is a syntax for this), but I've put it there just to give you an idea of what I'm thinking.

Thanks very much,
Joshua Wise
 
If there was only one Police Car type, that would be true. But the whole point of this thread is that there will only be one instance of each class, so PoliceCarZ28 would be instantiated once (inherriting from Z28, inherriting from Car) and PoliceCarCV would be instantiated once (inherriting from Crown Vic, inherriting from Car).

If I was going to be using these as widely instantiated classes, that would be a concern, and perhaps I could see some use in an interface, but since they will be one shot deals, I am missing the point of an interface implamentation.
 
riverguy said:
so one notices the colors of cop cars, along with the particular location of rocks and bushes, etc.
And there was me thinking riverguy was a normal human being.

Christiaan Baes
Belgium

If you want to get an answer read this FAQ faq796-2540
There's no such thing as a winnable war - Sting
 
....Driving for long stretches in rural desert gets boring....so one notices the colors of cop cars, along with the particular location of rocks and bushes, etc.
I took the "rocks and bushes" in the desert locale to mean latrine stops...as well as "cop concealment".

Forms/Controls Resizing/Tabbing
Compare Code
Generate Sort Class in VB
Check To MS)
 
...I guess I'm the only one who keeps my self entertained by noticing trival facts of my surroundings whilst driving down the dusty highways. [auto]
 
John,

I see what you mean. I guess since they took out the concept of multiple inherritance, the need for interfaces has become aparent to some people. I'm still wondering what the difference is between declaring a method in an interface and then importing that interface (and having to define the whole method in the class) and just defining the method independant of the interface.

I realize that it's there to keep methods uniform in their calling style, but otherwise, I can't see their point.

thanks,
Joshua
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top