Java Learning Note-design mode 9 (proxy mode)

Source: Internet
Author: User

Intention

Provides a proxy for other objects to control access to this object.

Public interface sourceable {public    void method ();
public class Source implements sourceable{     @Override public    Void Method () {         System.out.println Original method! ");}           }
public class Proxy implements sourceable{         private source source;         Public Proxy () {        super ();        This.source = new Source (); and adorner mode difference    }     @Override public    Void Method () {        System.out.println ("before decorator!");        Source.method ();        System.out.println ("after decorator!");}    }

The adorner mode differs from the proxy mode:

The adorner pattern focuses on dynamically adding methods on an object, whereas the proxy mode focuses on controlling access to objects. In other words, with proxy mode, the proxy class can hide specific information about an object from its clients. Therefore, when using proxy mode, we often create an instance of an object in a proxy class. Also, when we use adorner mode, it is common practice to pass the original object as a parameter to the decorator's constructor.

  

Transferred from: http://blog.csdn.net/zhangerqing/article/details/8239539

Java Learning Note-design mode 9 (proxy 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.