Interface very simple problem

D

Dave Johnson

Classes:

1-DataRepository Class - Contains (GetClientInfo Method, GetOrderInfo
Method)
2-Client Class
3-Order Class

The DataRepository Class has all the Functions that deals with the
Database such as (Client & Order) database methods.

Required:

make the Client Class have only Access to the GetClientInfo Method
and not also the GetOrderInfo Method and vice versa

How to do it using Interfaces??

can u please show it in a clear code, as i am new to Interfaces



Sharing makes All the Difference
 
T

Truong Hong Thi

interface IClientRepository
{
ClientInfo GetClientInfo(int clientID);
}

interface IOrderRepository
{
OrderInfo GetOrderInfo(int orderID);
}

public class DataRepository : IClientRepository, IOrderRepository
{
....
}

Then you will need a way to instantiate things, like directly
instantiating concrete classes, or using factories, dependency
injection, etc. depending on the level of flexibility you want.
Example:
public class DataFactory
{
IClientRepository GetClientRepository()
{
return new (or cached/singleton) DataRepository();
}

IOrderRepository GetOrderRepository()
{
return new DataRepository();
}
}

Hope this helps,
Thi
 

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