The adapter mode in the design mode is new, and the design mode is new.

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.