Design Pattern Basic Tutorial

adplus-dvertising
Facade Pattern
Previous Home Next

The facade pattern is used to simplifies to the complex system by providing a general interface or unified, which is a higher layer to these subsystems.

Benefit and use of the Facade Pattern
  1. Facade is used to reduce complexity of a system.
  2. It is reduce subsystem dependency, Decouple subsystems and improve portability.
  3. It is used to Make an entry point to your subsystems.
  4. Use in Minimization of the communication and dependency between subsystems.
  5. Also used in Security and performance consideration.

Example

//Create the interface
package r4r;
public interface general {
public void accessGeneral();
}
interface Special extends general {
public void accessSpecial();
}
interface Private extends general {
public void accessPrivate();
}

//Create the class and implement the interface
package r4r;
class GeneralInfo implements general {
public void accessGeneral() {
System.out.println("Hello this is General information");
}
    
}
class SpecialInfo implements Special{
public void accessSpecial() {
System.out.println("This is special infornation connected people");
}
public void accessGeneral() {}
   
}
class PrivateInfo extends  SpecialInfo implements Private, Special {
public void accessPrivate() {
System.out.println("This is private information private people connected");
}
// public void accessSpecial() {
//System.out.println("Welcome");
// }
public void accessGeneral() {
System.out.println("General people now connected");
}
    
}
public class facadetest {
public static void main(String[] args)
{
GeneralInfo g1=new GeneralInfo();
SpecialInfo s1=new SpecialInfo();
PrivateInfo p1=new PrivateInfo();
p1.accessPrivate();
p1.accessGeneral();
p1.accessSpecial();
}
}

Previous Home Next