Design Patterns skin mode - Summary

Design Patterns skin mode - Summary


In the last article, we simulate the appearance of a home theater project realization model to explain. This article, we summarize the appearance mode.

Source: Kaige Java (kaigejava) This paper consists of Kaige "23 design mode" in a series.

Kaige suddenly feel, home theater this case is inappropriate. Another plain. Access to the bank money. This case we have encountered it.

After we go to the bank, each window has a beautiful service for you. During our access to money, you only need to communicate and windows on it. We IDcard to, and then enter the password you will need to get the money. Let's analyze this process.

document_image_rId10.jpeg

Users access the money relative to the banking system, external personnel (system), the window attendant is an interactive window Foreign banks have to offer. Then we need to get IDCard, bank card, enter the password, the waiter will give us a window to print receipts, withdrawals, please sign leadership (if a larger amount of withdrawals was then) and so on operation window to help us deal with the waiter over. Finally, we have to be returned to us we need to make a cash deposit or have credentials.

We analyze the role:

External call the system (or client): If using the remote control or the theater must go to the bank to give us access to money

Complex systems: such as theater or was related to the banking system

In complex systems, the internal subsystems:

Bank example: the detectors, printers, safety deposit boxes, bank leadership.

Why should we use the facade pattern? What can solve the problem?

Reducing the complexity of the internal connection to access complex systems.

document_image_rId9.png


How to understand this sentence?

Go to the bank to withdraw money, if there is no window service, we need to count the money yourself, on your own printer, found himself leading the bank to sign and so on. It is not too much trouble. With the window attendant, since we need and attendant exchange, other do not shut up.

Therefore, we can get the appearance of critical code pattern wherein: when exchanged between the client and the complexity of systems, adding a layer between the two packages, the role of this layer is to call order dependencies etc. We are handled well.

advantage:

Reduce the interdependence between systems, improve the flexibility of the system, improve system security (think if you go to the bank to withdraw money, make your own money to get this feeling from the safe ~);

Between the client and the complex system is not coupled, and a system using the appearance-based coupling, to reduce the coupling;

Risks associated with low levels of developer prevention

Disadvantages:

Opening and closing does not meet the principles of software design, if you need to modify things, we must modify the window to the outside, a lot of trouble, inheritance rewrite is inappropriate.

scenes to be used:

为一个复杂的模块或者是子系统提供外界访问的模块;

子系统相对独立的

外观模式的目的:

为子系统中的一组接口或者一组功能提供一个一致的接口(界面),外管模式定义了一个高层接口,这个接口使得这一子系统更加容易使用。

本文来源:凯哥Java(kaigejava)

凯哥个人博客:www.kaigejava.com

本文地址:http://kaigejava.com/gwjeesns/article/edit/567

应用实例:

如果家庭影院以及银行取钱例子还不好理解。那么最简单的,JAVA中三层开发模式(MVC)就是典型的外观模式。这下是不是就好理解了.



Guess you like

Origin blog.51cto.com/kaigejava/2435321