Thursday, October 18, 2007

* Patterns : Facade Structural Pattern

'Facade Structural Pattern' is primarily used to unify and simply a set of interfaces of subsystems. This helps the client in using the interface with less effort.

Consider the class diagram below :


Above shows a typical scenario of a Bank where a new Customer approaches the Bank to open new account and also deposit some initial amount.

The Core Banking subsystems provide two different interfaces for Customer and Account and two different calls are required for Account opening and deposit of amount.

The Bank Facade shown above simplifies the new Customer creation, new Account Creation and deposit amount by providing a single interface/call to perform the required actions.

The Bank facade has following code :

// Acts as Facade
public class Bank
    Customer cust;
    Account acct;
    public void CreateCustomer(string name, string address, double initalDeposit)
        cust = new Customer(name, address);
        acct = new Account(name, 1234);

Download Full source code : Facade Structural Pattern Source Code

No comments:

Post a Comment