Facade Classes ????

D

Dave Johnson

I had a problem in my OO Design, the idea
is that i have a DataRepository Class That i want to only inherit from
it speacial methods accourding to the child class, like i want the
Client Class to just inherit GetClientInfo() from the DataReposiotry
Class and the Order Class just inherits GetOrderInfo() and so on

any ideas how to do this, it has been suggest to use facade classes!
would you be able to show how it can be done in a couple of lines of
code for demonostration as i am totally new to Facade Classes or suggest
any other approach!??

Thanks,




Sharing makes us all Better
 
Y

yoshijg

Facade classes are interfaces that simplify the actual object by
limiting what you see. (that's just my interpretation...I could be
wrong.)

For example, a "StudentRecord" could have grades, majors, advisors,
gpa, etc. But all that you may want to deal with is "Contact
Information." How would you determine what functions/properties deal
with the "Contact Info." Some people might put prefixes on their
function names, but that only goes so far. My preferred solution for
this a "IContact" interface.

I'm just going to give a quick step by step description... and there is
code snippet below. I used your "DataRepository" and "OrderInfo" as an
example.

1) I would create an "IOrder" interface that has a function called
"GetOrderInfo()". I would also suggest a function called
"GetOrderFacade()", which returns an instance of "IOrder".
2) Then have the DataRepository implement that interface.
3) To use the IOrder interface .... just say

orderObj = dataObj.GetOrderFacade();
orderObj.GetOrderInfo();


//************** Start Code *********************\\
public interface IOrder
{
object GetOrderInfo(); //Change the "object" to your liking.
IOrder GetOrderFacade();
}

public class DataRepository
: IOrder
{
public object GetOrderInfo()
{
return "Some Order data";
}

public IOrder GetOrderFacade()
{
return (IOrder)this;
}
}

//************** End Code **********************\\

So, whenever you want to deal with the "Order" infromation only, just
use the "GetOrderFacade()" and it will only return to you functions
related to "Order".

The benefits of this is that it limits the users accessible functions.
A "sales person" can only deal with "orders"...so just return them an
"IOrder" interface :)

Good luck... I hope this helps :)

josh
 

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