Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

"Head First Design pattern": appearance pattern

2025-01-31 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/03 Report--

Appearance mode

Appearance pattern definition: the appearance pattern provides a unified interface for accessing a group of interfaces in the subsystem. The appearance defines a high-level interface that makes the subsystem easier to use. The class diagram is as follows:

Main points:

The ● facade pattern provides a simple interface for complex subsystems without adding new functionality and behavior to subsystems.

The ● facade pattern realizes the loose coupling between the subsystem and the customer.

The ● facade pattern does not have classes that encapsulate the subsystem, but provides a simple interface. If the application requires it, it does not restrict customers from using subsystem classes. Therefore, we can choose between ease of use and versatility of the system.

The ● facade pattern focuses on simplifying the interface, and it is more likely to look at the entire system at the architectural level than at the level of a single class.

Appearance mode advantages:

● realizes the loose coupling between the subsystem and the client.

The ● client shields the subsystem components, reduces the number of objects that the client needs to process, and makes the subsystem easier to use.

Use the scene:

In the early stage of ● design, different layers should be consciously separated and appearance patterns should be established between layers.

During the ● development phase, the subsystem becomes more and more complex, and the added appearance pattern provides a simple calling interface.

When ● maintains a large legacy system, it may be very difficult to maintain and extend, but it also contains very important functions, so develop an appearance class for it so that the new system can interact with it.

Case 1: suppose we make a cinema at home, big screen TV, dvd, stereo, popcorn machine, there are a lot of equipment, our general process of watching TV is:

● turns on the power first.

● then turn on the TV.

● then open dvd.

● then turn on the stereo.

● then turns on the popcorn machine.

● and then, and then shut down? We deal with a lot of things ourselves, and then we can introduce the appearance pattern to simplify, remember, the appearance pattern is to simplify the interface and simplify the subsystem calls. After the transformation, we can press the button of the remote control to deal with all these steps, the class diagram is as follows:

Design principle: the principle of least knowledge, only talk to friends.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report