Three minutes to understand "appearance mode"--easy to master in design mode

Source: Internet
Author: User

Examples of real life:

Now popular stocks, shareholders generally hold a good number of stocks, and investors need to pay attention to the hands of the N stock trend, at any time for different stocks to make different decisions, so feel good tired, so some people choose to buy funds. The fund is still fried stock, but the fund agency took the investor's money to buy n stocks, and we just buy a fund is enough, the management of n stocks to the fund to toss, we instantly feel good relaxed.

The code world is the same, each stock is a class, each fund is a class, investors are the users of these classes. If investors directly operate a number of stock classes, which will lead to the operation of the shareholders class is very complex, then the shareholder class and the whole system of the Lotus is very high. If the introduction of a fund class, the operation of the stock class all by the Fund class to complete, the investor class only need to interact with the Fund class, which greatly reduces the complexity of the shareholder class, reduce the share between the class and the system of the Lotus degree.


Class diagram of the appearance pattern:


Now there are a lot of subsystems, they all have external interface, if let the client directly interacts with these subsystems, then the client code is too complex, this time introduced a skin class to handle the interaction with each subsystem, the client simply call the appearance of simple interface to operate the subsystems.


The use of appearance patterns in MVC:

The MVC pattern divides the entire system into action, service, and DAO layers. The action layer is equivalent to the client, the service layer is equivalent to the Appearance class, the DAO layer is equivalent to each subsystem.

If there is no service layer, then the action has to interact directly with DAO, and we know that a function may need to be implemented in more than one DAO, which causes the code in the action to be too complex. So we introduced the service layer in the middle of the action layer and the DAO layer, encapsulating the complex functions of the DAO layer in the service layer's functions, the service layer provides a series of simple interfaces to the action layer, which makes the code of the action layer simple and clear.


When do I use appearance mode?

1. During the system design phase, the MVC pattern is used to leave the action, Service, and DAO layers separated, which provides a simple interface for the operation of the complex DAO layer, which reduces the coupling between the action and the DAO greatly.

2. In the development phase, subsystems become more and more complex due to continuous refactoring, and most design patterns produce many small classes, which is good, but it also brings difficulties in using external calls to their user programs. Increasing the appearance of the class can provide a simple interface to the user program, reducing their dependency.

3. In the maintenance period, if the maintenance of a large legacy system, it may be very difficult to extend and maintain the system, but this system contains important features we must use it, if directly call these features may lead to the client program is very complex, so we can use a skin class, Provides a simple and clear external interface to complex legacy code.



The official definition of the appearance pattern:

Provides a consistent interface for a set of interfaces in a subsystem that defines a high-level interface that makes this subsystem easier to use.



The official definition of the appearance pattern:

Provides a consistent interface for a set of interfaces in a subsystem that defines a high-level interface that makes this subsystem easier to use.

Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

Three minutes to understand "appearance mode"--easy to master in design mode

Contact Us

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

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.