Monday, April 12, 2010

.NET Facade design Pattern with Example

What is Facade design pattern
The facade pattern is a stuctural design pattern that is used to simplify access to functionality in complex designed subsystems. The facade class provides a simple, interface that hides the implementation details of the underlying code.It create relationship between classes and enities.

One example use of the facade pattern is for ATM system.ATM System shows only interface and hides all implmentation details.ATM perform various operation like Withdraw,Tranfer etc but user cant see the what code written behind the interface.


UML diagram of the two classes and the relationship to the Facade (BankOperation) Class. You can see from this partial diagram that there will be multiple classes and methods within the classes.

■Facade. This class contains the set of simple functions that are made available to its users and that hide the complexities of the difficult-to-use subsystems.
■Class.These classes contain the functionality that is being presented via the facade.

First, I will show the code for the three service classes. The first service class is for Withdraw and Deposite from the account. The shell code for this class is shown below, and a simple call to the method will perform the Withdraw operation.