1. Observer design pattern:
Intent: define a one-to-many dependency between objects, and when the state of an object changes, all objects that depend on it are notified and automatically updated.
Main Solution: an object state changes to other object notification issues, and to consider the ease of use and low coupling, to ensure a high degree of collaboration.
when to use: the state of an object (the target object) changes, and all dependent objects (the Observer object) are notified of the broadcast notification.
How to Solve: using object-oriented technology, you can weaken this dependency.
Key code: There is a ArrayList in the abstract class that holds the observers.
2. Proxy mode:
The so-called agent is one person or institution acting on behalf of another person or institution. In some cases, a client does not want or cannot refer directly to an object, whereas a proxy object can act as an intermediary between the client and the target object.
The proxy mode class diagram is as follows:
Roles in proxy mode:
Abstract Object role: declares a common interface between the target object and the proxy object, so that the proxy object can be used wherever the target object can be used.
target Object role: defines the target object that the proxy object represents.
proxy Object role: the proxy object contains a reference to the target object, so that the target object can be manipulated at any time, and the proxy object provides the same interface as the target object so that the target object can be substituted at any time. Proxy objects typically perform an operation before or after a client call is passed to the target object, rather than simply passing the call to the target object.
Java Design Patterns