Design mode--proxy mode

Source: Internet
Author: User

There is a fixed interface with some special logic, and this interface does not satisfy these special logic, the use of proxy mode to integrate special logic into the special class

Abstract role: A business method that declares the real role implementation through an interface or abstract class.   Agent role: the implementation of abstract role, is the real role of the agent, through the real role of the business logic method to implement the abstract method, and can attach their own operations.   Real role: Implement abstract roles, define the business logic to be implemented by the real role, for proxy role invocation.     //abstract roles     public interface italk{            publicly void talk ( String language); }    //Real role     public class people implements italk{            public void Talk (String language) {                &NBSP ;  //xxxxx           }   }     //agent role     Publi C class  peopleproxyforsing  implements italk{            italk _talk ;            public peopleproxyforsing   (Italk talk) {      & nbsp         _talk=talk;           }            &nbSp           public void Talk (String language) {              &NBS P     //todo attach own special implementation _talk.talk (language);//Invoke Real role implementation//todo attach own special implementation       &NBSP ;    }   }

Design mode-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.