JDK Source Reading-3-design mode-structured mode

Source: Internet
Author: User

1. Adapter (Adapter)

    • java.util.Arrays$ArrayList(java.util.Arrays#asList());

 这里要特别注意,这里的ArrayList是Arrays的内部类不是java.util.ArrayList.这里的ArrayList是外部不可见的,用来把一个array适配成List.

 650) this.width=650;" src="http://s3.51cto.com/wyfs02/M00/70/2D/wKiom1WzMZvwKSaiAADNrYSrW3c770.jpg" title="ArrayList.jpg" alt="wKiom1WzMZvwKSaiAADNrYSrW3c770.jpg" />

Sample:

String a[] = new string[]{"123", "ABC", "XYZ", "ddd"}; List List = Arrays.aslist (a);


    • java.io.InputStreamReader(InputStream)

 InputStream --> Reader

650) this.width=650;" src="http://s3.51cto.com/wyfs02/M01/70/29/wKioL1WzNUWRYQmNAACkuN3EKLk401.jpg" title="InputStreamReader.jpg" alt="wKioL1WzNUWRYQmNAACkuN3EKLk401.jpg" />

 

    • java.io.OutputStreamWriter(OutputStream)(Returns a Writer )

      See the top two


2. Combination mode (Composite)

    • java.awt.Container#add(Component)

650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M01/70/29/wKioL1WzNwmCKMqcAABxw-Lvmwg409.jpg "title=" Container.jpg "alt=" Wkiol1wznwmckmqcaabxw-lvmwg409.jpg "/>


3. Adorner (Decorator)

    • All Writer 的子类有一个构造函数接受同类型的实例,下面用一个例子来图示 , , , follow Reader . java.io.InputStream OutputStream

650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M01/70/2D/wKiom1WzNzSwfcv9AAB6FTOplQc551.jpg "title=" Bufferedinputstream.jpg "alt=" Wkiom1wznzswfcv9aab6ftoplqc551.jpg "/>

    • 还参见java.util.Collections, of checkedXXX() , ,. synchronizedXXX() unmodifiableXXX()方法


4. Appearance mode (facade)

    • interfaces such as Iconnection in JDBC


5. Enjoy meta mode (Flyweight)

    • java.lang.Integer#valueOf(int)(BooleanByteCharacterShort, Long )

6. Agent mode (proxy)

    • java.lang.reflect.Proxy


JDK Source Reading-3-design mode-structured mode

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.