java4all@1986 java. Powered by Blogger.

What is meant Facade Design Pattern?

>> Friday, May 27, 2011

FACADE DESIGN PATTERN:
   It comes under Structural Design Pattern.Make a complex system simpler by providing a unified or general interface, which is a higher layer to these subsystems.


Where to use & benefits


  • Want to reduce complexities of a system.
  • Decouple subsystems , reduce its dependency, and improve portability.
  • Make an entry point to your subsystems.
  • Minimize the communication and dependency between subsystems.
  • Security and performance consideration.
  • Shield clients from subsystem components.
  • Simplify generosity to specification.
  • Related patterns include 

Example

JDBC design is a good example of Façade pattern. A database design is complicated. JDBC is used to connect the database and manipulate data without exposing details to the clients.
Security of a system may be designed with Façade pattern. Clients' authorization to access information may be classified. General users may be allowed to access general information; special guests may be allowed to access more information; administrators and executives may be allowed to access the most important information. These subsystems may be generalized by one interface. The identified users may be directed to the related subsystems.
interface General {
    public void accessGeneral();
}
interface Special extends General {
    public void accessSpecial();
}
interface Private extends General {
    public void accessPrivate();
}

class GeneralInfo implements General {
    public void accessGeneral() {
 //...
    }
    //...
}
class SpecialInfo implements Special{
    public void accessSpecial() {
        //...
    }
    public void accessGeneral() {}
    //...
}
class PrivateInfo implements Private, Special {
    public void accessPrivate() {
 // ...
    }
    public void accessSpecial() {
 //...
    }
    public void accessGeneral() {
 // ...
    }
    //...
}

class Connection {
   //...
    
   if (user is unauthorized) throw new Exception();
   if (user is general) return new GeneralInfo();
   if (user is special) return new SpecialInfo();
   if (user is executive) return new PrivateInfo();
   //...
}
The above code example illustrates that the whole system is not exposed to the clients. It depends on the user classification.




0 comments:

Post a Comment

FaceBook Login

HTML/JAVASCRIPT

HTML/JAVASCRIPT

HTML/JAVASCRIPT

HTML/JAVASCRIPT

Total Pageviews

STATCOUNTER

  © Blogger template Simple n' Sweet by Ourblogtemplates.com 2009

Back to TOP