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!

can i set a derived variable outside a constructor

Status
Not open for further replies.

modika11

Programmer
Jan 31, 2008
20
Hi All,

i have created an architecture. I have a base company class, of which client and vendor inherit. each of the client and vendor classes have their own set of configurations that are specific to them. So in my base company class i create a shared property which is an an interface (iCompanySettings) of which clientSettings and vendorSettings implement. This all works (kinda) but the problem i have is i have to instantiate a instance or clientSettings or vendorSettings in the constructor of the client and vendor classes. This is not really a problem for my normal methods, but i am trying to define some shared (static) methods which break as no instance has been created before they are used. is there a way in the derived classes that i can set the settings variable from the base class outside the constructor whithout it erroring or is their a more elegant solutin to the one ihave implemented?

Any thoughts would be great.

Thanks,

Rob
 
Not enough information to answer. Suppose you lay out your classes, interfaces, and methods involved and see if we can solve it.
 
Hi Rob,

I don't get it. A static method has nothing to do with any instance, so it should not be interested in any settings given to an instance.

Furthermore, if a method IS interested in instance data, it should be an instance method. So the answer should be to make the methods non-static.

That said, I think static methods are a bit overrated. What is against creating an instance? Instances have a creation time and are in a scope. In other words: Instances are under control. Static members are just like global variable/functions. So why attempt using an object oriented language if you want to do things the procedural way?

+++ Despite being wrong in every important aspect, that is a very good analogy +++
Hex (in Darwin's Watch)
 
Hi Guys,

I have just started with OO and i think i look at things a bit too much. I have managed to apply a solution (i think). I created a base company class which itself contains common implementations of functions (insert, update, delete, getByID etc) and then have client and vendor which derive from it. At the moment i dont have to override the base functionality but i know i will eventually extend with Vendor so i am just trying to plan ahead, with the settings what i do (VB.Net) is shadow the shared property in the base class which overrides it in the child class, that way i get my individual settigns for each individual client class. It all seems to be working now.

What i did before was try and apply a solution (with additional classes etc) to a problem that simply wasnt there. I am learning slowly, and i guess i am going to make a few more mistakes along the way, but aslong as i am learning then i guess you cant argue :)

Thanks for your responses.

Rob
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top