I gave a reference article when I learned about the decoration mode in disorder. It compares the decoration mode with the agent mode. Naturally, this is what OneCoder needs to understand now. First, review the six principles of the design model: six principles of the design model (derived from zz563143188.iteye. comblog1847029) 1. Open and Close principles (OpenClosePrinciple)
I gave a reference article when I learned about the decoration mode in disorder. It compares the decoration mode with the agent mode. Naturally, this is what OneCoder needs to understand now. First review the six principles of the design model: the six principles of the design model (from: http://zz563143188.iteye.com/blog/1847029) 1, the Principle of Open Close Principle
I gave a reference article when I learned about the decoration mode in disorder. It compares the decoration mode with the agent mode. Naturally, this is what OneCoder needs to understand now. First review the six principles of the design model: the six principles of the design model (from: http://zz563143188.iteye.com/blog/1847029)
1. The Principle of Open Close Principle is to Open the extension and disable the modification. When the program needs to be expanded, you cannot modify the original code to achieve a hot swapping effect. So in a word, it is easy to maintain and upgrade the program to make it more scalable. To achieve this, we need to use interfaces and abstract classes. We will mention this in the specific design. 2. The Liskov Substitution Principle is one of the basic principles of object-oriented design. In the Rys replacement principle, subclasses can certainly appear where any base class can appear. LSP is the cornerstone of inheritance reuse. Only when the primary class can replace the base class and the functions of the software unit are not affected can the base class be reused, the category class can also add new behaviors based on the base class. The Li's replacement principle is a supplement to the "open-closed" principle. The key step for implementing the "open-close" principle is abstraction. The inheritance relationship between the base class and sub-classes is the specific implementation of abstraction. Therefore, the Li's replacement principle is the standard for the specific steps to implement abstraction. -- From Baidu encyclopedia 3. Dependence Inversion Principle is the basis of the open and closed principles. Specific content: True interface programming depends on abstraction rather than specifics. 4. The Interface Segregation Principle means that it is better to use multiple isolated interfaces than to use a single Interface. We can see from this that the design mode is a software design idea, starting from the large-scale software architecture, for the convenience of upgrading and maintenance. So it appears many times above: reducing dependencies and reducing coupling. 5. Demeter Principle is the least known Principle, which means that an entity should interact with other entities as little as possible, this makes the system function modules relatively independent. 6. The Composite Reuse Principle is to use the synthesis/aggregation method as much as possible, rather than inheritance.
Proxy mode: provides a proxy for other objects to control access to this object. Let's look at a picture: here we imagine a simple scenario of selling houses. If there is no proxy, the owner of the house wants to sell the house. He/she needs to publish his/her own information, take the buyer to the House, and handle the handover procedures. At this time, the homeowner found it too troublesome. So he invited the proxy HouseProxy to take charge of everything except the formalities that the homeowner must attend. This is exactly the application scenario in the proxy mode: intelligent guidance refers to the agent to process other things when calling real objects. Compared with the decoration mode, it feels very similar, so there will be articles that have been mentioned before. The proxy mode is a proxy that handles all other things, and the decoration mode requires a series of various "talents. The implementation code is simple:
/*** Created by OneCoder on 2014/11/24.*/public class HouseOwner implements ISellHouse { @Override public void sellHouse() { System.out.println("Sell my house.") ; }}/*** Created by OneCoder on 2014/11/24.*/public class HouseProxy implements ISellHouse { private ISellHouse seller; public HouseProxy(ISellHouse seller) { this.seller = seller ; } @Override public void sellHouse() { System.out.println("Proxy: Publish the information."); System. out.println("Proxy: Contact the buyer."); seller.sellHouse(); System. out.println("Proxy: Get commision."); }}There seems to be nothing to say. OneCoder's self-perception is that they can be divided and used to achieve the goal. PS:
1. Recently, blog updates are slow, and there are many things in the house. However, you must stick to it in learning. Even if it is a race against the tortoise and the rabbit, I am moving forward.
2. the blog traffic has exceeded recently (15G/month) because it has been received from IP address 114.215.138.184 (love paper ?) . Limited energy and limited economy (traffic is sufficient again .), Therefore, it may be a long process for OneCoder to gradually move its blog to github. io...Crawlers can... Endless crawling .. No ....
Original article address: out-of-the-box design mode-proxy mode. Thank you for sharing it with the original author.