An example of-java design pattern for interview questions

Source: Internet
Author: User
Interview questions-java Design Pattern Example 1, adapter mode

Involves three roles: Target destination interface, Adaptee source role, adapter adapter,adapter The source interface to the target interface, inherits the source interface, and implements the target interface .

Many examples of Java I/O operations are:

InputStreamReader the inputstream to reader; you need to inherit inputstream to implement reader.

OutputStreamWriter the outputstream adaptation to Writer;

StringReader applies the String class to Reader;

2. Adorner mode

Involves three roles: Component abstract component roles, concretecomponent implements all functions of the abstract component, decorator adorner role, it holds a reference to a Component object instance, defines an interface that is consistent with the abstract component, Concretedecorator specific decorator implementations.

Adorner mode in Java I/O: FilterInputStream class;

    

Note: Both adapter and adorner modes are wrapper modes, and they appear to be a reference for wrapping a class or object, but the purpose of using them is different; the meaning of adapter mode is to change the interface to achieve the purpose of re-use, the adorner mode is to maintain the original interface, enhance the function of the original object.

An example of-java design pattern for interview questions

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.