Data Repository Class & OOP Inheritance

D

Dave Johnson

I have made a Data Repository Class that holds all the Methods for the
Objects that i use in my System such as Order,Client,etc

Example for what i want to do: In the Client Class I want to inherite
from the "DataRepository Class" **ONLY** the methods that is related to
the Client such as GetClientInfo(). and the Same for the Order Class i
want to inherite **ONLY** the methods related to the Order such as
GetOrderIno()

how to do this in OOP? if anyone is able do demostrate and example for
such CASE of Selective Inheritance that would be Very Helpful.

thanks

Sharing makes us all Better
 
F

Frans Bouma [C# MVP]

Dave said:
I have made a Data Repository Class that holds all the Methods for the
Objects that i use in my System such as Order,Client,etc

Example for what i want to do: In the Client Class I want to inherite
from the "DataRepository Class" ONLY the methods that is related to
the Client such as GetClientInfo(). and the Same for the Order Class i
want to inherite ONLY the methods related to the Order such as
GetOrderIno()

how to do this in OOP? if anyone is able do demostrate and example for
such CASE of Selective Inheritance that would be Very Helpful.

I think you made a mistake. Instead of adding GetOrderInfo() to the
Datarepository class, you should have made GetInfo() or GetEntityInfo().

Then, you override in every derived class, like Order, Client,
Customer, Product etc., the GetEntityInfo() method. So,
Order.GetEntityInfo() (or Order.GetInfo()) will return the order info,
or whatever data, and in other derived classes it does the same, but
for that particular type. This is polymorphism.

if you then also define an interface, like IEntityAccess, and that
interface has the method GetInfo() or GetEntityInfo(), you can write
generic code which fetches order, customer, product etc, by using that
interface and the method every object implements. You can of course
also cast to the datarepositoryclass and to do the same.

Frans

--
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top