Appearance mode: The appearance pattern is a very common pattern, in the software development process, the client program is often coupled with the internal subsystem of the complex system, which causes the client program to change with the subsystem, however, in order to decouple the internal subsystem of the complex system from the client, it has the appearance mode, Also known as "façade" mode. Now let me introduce you to the knowledge of the appearance pattern.
first, the definition:Provides a consistent interface for a set of interfaces in a subsystem that defines a high-level interface that makes the subsystem easier to use.
Second, the purpose:Reduce the complexity of the system.
Third, contact life:Why is it that it reduces the complexity of the system? For example, when we cook for the holidays and cook our own meals, we need vegetables, rice, bowls, chopsticks, and what is the interaction between the classes, and what if we buy rice outside?
Dining in a restaurant has been designed to a pattern--the appearance of the model. My understanding of the appearance pattern: Put a lot of subcategories into a bag, only one mouth, this mouth is the façade appearance class, the equivalent of the hotel waiter, we just need to tell the waiter what to eat, they can give to make, and without us and vegetables, rice and other interaction. Thus, through the appearance pattern, we can reduce the coupling of the system, the class can not interact with each other, but through a visual class to achieve access to A and B, greatly reducing the coupling.
Iv. Advantages and disadvantages:1. Advantages:The perfect embodiment relies on reversal and Dimitri. (1) The appearance mode shields the customer from the subsystem components, simplifies the interface, reduces the number of objects processed by the client and makes the subsystem easier to use. (2) It realizes the loose coupling relationship between the subsystem and the customer, and the function components inside the subsystem are tightly coupled. Loose coupling makes the components of a subsystem change without affecting its customers.
2. Disadvantages:In object-oriented software systems, there are many classes, the introduction of the appearance of the model to reduce the coupling between the classes, but if you want to introduce more classes, but need to change the appearance of the class, this view, the appearance of the model is not in line with the opening principle, although he made it easy to change
v. Application:1,Appearance pattern structure diagram:
2, code display: First write out four subsystems of the class: class subsystemone { public void methodone () { console.writeline ("subsystem method one"); } class Subsystemtwo { public void Methodtwo () { console.writeline ("subsystem method two"); } class Subsystemthree { public void Methodthree () { console.writeline ("Subsystem Method III"); } class Subsystemfour { public void Methodfour () { console.writeline ("subsystem offense four");        &NBSP} Introduce appearance classes to reduce interaction between subsystem classes: //need to know all the subsystems ' methods or attributes, and make a combination for outside call class facade { SubSystemOne one; SubSystemTwo two; SubSystemThree three; SubSystemFour four; public facade () { one = new subsystemone (); two = new subsystemtwo ( ); three = new Subsystemthree (); four = new Subsystemfour (); } public Void methoda () { console.writeline ("\ n method combination A ()---"); one. MethodOne (); &nbsP; two. Methodtwo (); four. Methodfour (); } public Void methodb () { console.writeline ("\ n method Group B ()---"); two. Methodtwo (); three. Methodthree ();        &NBSP} } Client invocation: // Because of the façade's role, the client can not know the existence of three subsystem classes at all, the code is relatively concise static void main (String[] args) { facade facade = new facade (); façade. MethodA (); façade.MethodB (); console.read (); }
3, when to use. Initial design: Consciously separate the two layers from each other.
Development phase: Subsystems tend to become more complex because of the constant reconfiguration of fireworks, most patterns are used to produce many very small classes, this is good, but to external invoke their user program brings difficulty in using, increase appearance ffacade can provide a simple frontal interface, reduce their dependencies.
Maintenance: Develop a façade class for the new system when it is difficult to maintain and expand, provide a clearer and simpler interface for designing rough and highly complex legacy code, and allow the new system to interact with the façade object, and the façade interacts with the legacy code for all the complex work.
Vi. Summary:Introducing the Appearance class, by wrapping the class, the implementation of a high-level interface, reducing the complexity of the system, which is very similar to the adapter mode, but the appearance mode and adapter mode is different: The adapter mode is to wrap an object to change its interface, and the appearance mode is a group of objects "packaging" Up to simplify its interface. But let's not forget that if we introduce a new subsystem, we need to modify the subsystem so that it does not conform to the opening and closing principles, so each model has its good side and its bad side. Finally, I would like to ask you a question: The Simple factory model does not conform to the opening and closing principles, and the appearance of the model does not conform to, why the appearance of the model can be grouped into 23 modes, and simple factory is not. If the simple factory model is because the factory method model has been corrected, so there is a factory method model can be, but the appearance of the model does not conform to the opening and closing principles, classified into 23 kinds of mode how to say it. Thank you for your communication.
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.
A Free Trial That Lets You Build Big!
Start building with 50+ products and up to 12 months usage for Elastic Compute Service