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 Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Object Help with extending a supertype

Status
Not open for further replies.

modika11

Programmer
Jan 31, 2008
20
Hi All,

I am getting my head round OO and am trying to write better applications usimg the techniques available. I am new to this so still get majorly stumped at times.

I have a baseCompany supertype which is abstract and from that i create two subtypes of my base which are client and vendor. Client maps to the base class, but vendor exposes some extended properties. Where i am having some difficulty is creating the client and vendor data provider class. I would like if possible to define some sort of companyProvider interace/abstract class that defines the methods that both the classes will use, but i am a bit confused as the vendor object exposes extra properties so does that mean i cant utilise a base in this instance.

Any help will be much appreciated.

Rob
 
If I understand you correctly, then client and vendor will extend baseCompany, and implement companyProvider. Then you can reference either class as a baseCompany or a companyProvider, but only use the methods define in those classes/interfaces. If you need to access the additional properties in vendor and you know its a vendor, there shouldn't be any problem. If you only know its a companyProvider, then you'll need to have all the properties in the companyProvider interface, and just not use them when they aren't applicable. Hope this helps.
 
Hi Jaxtell, i am not sure i explained myself in the best way, most of what you understood is correct but i dont think i explained the whole structure.

I have a baseCompanyDetails class of which is inherited by
clientDetails and VendorDetails as you correctly understood. These are basic objects that i created so i can pass them round the different teirs of my application, they are simple as i dont define any methods in them (apart from the constructor) simply properties.

then it comes to the stage where i want a provider class that will implement my data access logic and this is where i get stumped.

At first i thought about defining an interface and simply define the methods that are required i.e. getCompanyByID, getCompaniesCollection etc. ClientProvider and VendorProvider will them implement this interface and implement the functions, but i am little confused with the object part of it as my interface will define the use of my companyBaseClass but in my subType i want them to use their respective types, is this just a matter of implementing the function and changing the return type, or would it be better that my companyProvider be an abstract class and i simply override the methods i want, but that just seems a bit pointless as i might aswell just define clientProvider and vendorProvider seperatly but i dont want to do that as they are the same object apart from some extended properties.

Sorry i may have cofused it even more???

Rob
 
You might consider a structure that creates the base data provider class and then adds a property class that's associated with it. There would be a one to many relationship between the two. That way, you can customize the properties of any data provider and still retain your concept of interface.

By the way, that's the way ADO is constructed.

One other point is that if there are aspects of the base class that are implemented in the same way, you might consider not using a pure interface, instead working with implementation inheritance. This avoids redundant coding in your interface implementations.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top