Laugh and understand design patterns-java--Agent mode

Source: Internet
Author: User

Let's talk about agent mode today.
What is the proxy mode? I am very busy, busy no time to talk to you, then you want to find me, I will first find my agent. Today is the scene of the boss, the Secretary, the staff.
The average employee can't see the boss. But if the employee is doing well and wants a promotion and a raise.
That's when the boss's assistant showed up. So, this time we have
Boss interface.
Assistant Class
Professional class:
An employee
—————————————————————
Boos interface.

Public interface Boos {public
    void Add_money ();  Pay raise public
    void Add_power ()/Promotion
}

Assistant class; Implement boss interface

public class Assistan implements boos{
    private Boos Boos;
    Public Assistan (Boos Boos) {
        this.boos = Boos;
    }
    public void Add_money () {
      This.boos.add_money ();
    }
    public void Add_power () {
      this.boos.add_power ();    
    }
}

A hard worker red. Basic appeal. Promotion pay

public class Red implements com.it.pcc.proxypatterns.boos{public
    void Add_money () {
        System.out.println ("Raise ");
    }
    public void Add_power () {
        System.out.println ("promotion");
    }

Workplace:

public class Staff {public
    static void Main (string[] args) {red
        red =new red ();
        Assistan Assistan =new Assistan (red);
        Assistan.add_money ();
        Assistan.add_power ();
    }

Basically, I want a raise. Look for the boss. The boss is not here. But the Assistant can act as the boss of these two functions.
One day is more likely to be too superficial to understand some patterns. And it's a short time to find the right scene. Today it feels like there are some flaws in this agent mode. Try to get more nutrients.

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.