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.
A client is exposed to certain set of methods like just getting a single instance of database connection or closing it when not required.
Another possibility is designing security of a system 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 oneinterface. The identified users may be directed to the related
subsystems.
interface PublicMethod{
public void accessPublicMethod();
}
interface SpecialMethod extends PublicMethod{
public void accessSpecialMethod();
}
interface PrivateMethod extends PublicMethod {
public void accessPrivateInfo();
}
class PublicInfo implements PublicMethod{
public void accessPublicMethod() {
//...
}
//...
}
class SpecialInfo extends PublicInfo implements SpecialMethod {
public void accessSpecialMethod() {
//...
}
}
class PrivateInfo extends SpecialInfo implements PrivateMethod {
public void accessPrivateMethod () {
// ...
}
//...
}
The above code example illustrates that the whole system is not exposed to the clients. It depends on the user classification.
When a person is exposed to special information, that person is allowed to access public information also. When a person is exposed to private information, that person is allowed to access public and special information as well.
1 comments :
very informative . another article i would suggest is this one
Post a Comment