码迷,mamicode.com
首页 > 编程语言 > 详细

Java 设计模式 之 调停者模式

时间:2018-06-28 10:14:15      阅读:161      评论:0      收藏:0      [点我收藏+]

标签:content   new   and   模式   ide   str   hand   Owner   equals   

http://www.verejava.com/?id=16999137231072

package com.mediator.theory;

public class TestMediator
{
    public static void main(String[] args)
    {
        Mediator mediator=new MediatorImpl();
        mediator.handle("rent");
        mediator.handle("sale");
    }
}





package com.mediator.theory;

public interface Mediator
{
    public void handle(String content);
}





package com.mediator.theory;

public class MediatorImpl implements Mediator
{
    private HouseOwner owner1;
    private HouseOwner owner2;
    
    public MediatorImpl()
    {
        owner1=new HouseRent();
        owner2=new HouseSale();
    }

    @Override
    public void handle(String content)
    {
        if("rent".equals(content))
        {
            owner1.action();
        }
        if("sale".equals(content))
        {
            owner2.action();
        }
    }

}





package com.mediator.theory;

public interface HouseOwner
{
    public void action();
}





package com.mediator.theory;

public class HouseRent implements HouseOwner
{

    @Override
    public void action()
    {
        System.out.println("客户来了需要租房");
    }

}






package com.mediator.theory;

public class HouseSale implements HouseOwner
{

    @Override
    public void action()
    {
        System.out.println("客户来了需要卖房");
    }

}

http://www.verejava.com/?id=16999137231072

Java 设计模式 之 调停者模式

标签:content   new   and   模式   ide   str   hand   Owner   equals   

原文地址:https://www.cnblogs.com/verejava/p/9237049.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!