Facade in design pattern - family articles
This year's 11th National Day, I stayed at home, I enjoyed the warmth. First let me introduce my family members:
WiFe
Daughter
I (ME)
We are all homes of family, we are in home. As our country is "China", foreigners call us Chinese, but in China's large family, including Han, Hunt, Mong,. . . Waiting for 56 nations.
It can be seen that we are in a unified identity, or a unified appearance (FACADE).
well, let's get back to business.
1, here, first define all members of the family:
Wife (Wife):
Public class wife {
protected wife () {
System.out.println ("Wife is great!");
}
}
Daughter:
Public class daugging {
protected daughter () {
System.out.println ("Daughter Cute!");
}
}
I (me):
PUBLIC CLASS ME {
protected me () {
System.out.println ("I love my home!");
}
}
2. Define a family exhibition (FamilyoutShow) class:
Public class familyoutshow {
Public void myfamily () {
Wife mywife = new wife (); // My wife
Daughter mydaughter = new daughter (); // My daughter
ME me = new me (); // I myself
}
}
3, write test classes:
Public class myfamilytest {
Public static void main (String [] args) {
Familyoutshow myfamily = new familyoutoutshow ();
Myfamily.myfamily ();
}
}
4, explanation:
A: Facade definition: Provide a consistent interface for a set of interfaces in the subsystem.
B: Use a unified external interface to reduce the complexity of the system and increase flexibility.
C: As can be seen from the example, the outside world just visits the FamilyoutShow class, but not directly to the member class. This, for example, a new member class (for example, the son class), as long as the family exhibition (FamilyoutShow) can be modified, without modifying the call.
5, especially gratitude: Thanks to many netizens such as WINDCSN, FLYINGWIND, ACDSEE, so I made some modifications, I hope to explain the problem. Everyone's support is the best encouragement for me, thank you very much!