The adapter mode in the design mode is new, and the design mode is new.
Point by point, client at me now
There are two implementation modes: Class adapter and Object Adapter. The difference between the two is that the implementation method is different, A method of combination. in addition, it can be divided into two types for the purpose of use. the difference between special and default adapters is that the purpose is different. One method is to reuse the original code and not match the current interface, and the other is to provide the default implementation, avoid subclass implementation methods that should not be implemented.
The adapter is a remedy
- It involves the observer mode to continue to consolidate the transfer
- When we need to reuse the functions of a class and want to implement the functions of an interface, we actually use inheritance to implement it.
- This is the simplest adapter mode, that is, the class adapter.
- For example, the User extends BaseUser is very common. Then, I need to extend the function to get an ObservableUser inherited from the User, so that the User will be observed.
- The implementation method is as follows:Object Adapter
- The problem is obvious. If there are other classes that need to be extended, We can inherit the class from the ObservableBaseEntity extends BaseEntity sub-classes.
- The purpose here can be viewedSpecial Adapter
- However, sometimes our interface design is relatively large, that is, there are too many methods.Default AdapterIt appears.
- We have a mobile phone interface.
- Mobile phones generally have some default conditions, such as phone calls. However, for some special reasons, some mobile phones are not allowed to access the Internet. The default adapter is used to implement the null method by default, then you only need to re-write this class.
This article is short mainly becauseObserver Mode,Minimize InterfacesAndRys replacement principleReview