Definition
Provide a unified interface to a set of interfaces in a subsystem. Façade defines a higher-level interface that makes the subsystem easier to use.
UML class diagram
Participants
The classes and/or objects participating in this pattern are:
- Facade
delegates client requests to appropriate subsystem objects.
- Subsystem classes
handle work assigned by the Facade object.
have no knowledge of the facade and keep no reference to it.
Sample code in C#
public class OrderFacade
{
//Places an Order and Returns an Order ID
public int placeOrder(int CustomerID, ListProducts)
{
Order anOrder = new Order();
OrderLine anOrderLine = new OrderLine();
Address DespatchAddress = Address.getCustomerDespatchAddress(CustomerID);
int OrderId = anOrder.requestOrderID();
anOrder.createOrder(OrderId, DespatchAddress);
anOrderLine.addOrderLinesToOrder(OrderId, Products);
return OrderId;
}
}
//order class
public class Order
{
public int requestOrderID()
{
//Creates and Returns a Unique Order ID
}
public void createOrder(int OrderId, Address DespatchAddress)
{
}
}
//OrderLine Class
public class OrderLine
{
public void addOrderLinesToOrder(int OrderId, ListProducts)
{
}
}
//Public Customer
public class Address
{
public static Address getCustomerDespatchAddress(int CustomerID)
{
return new Address();
}
//Address properties
}
public class BasketItem
{
//BasketItem Properties
}
-
-
Lee(713)
-
Enlace permanente