【桥接模式】【辣椒、不辣 牛肉、猪肉 面 组合】

来源:互联网 发布:网络推广代运营协议 编辑:程序博客网 时间:2024/04/28 00:19
/** * Description: * <br/>网站: <a href="http://www.crazyit.org">疯狂Java联盟</a>  * <br/>Copyright (C), 2001-2012, Yeeku.H.Lee * <br/>This program is protected by copyright laws. * <br/>Program Name: * <br/>Date: * @author  Yeeku.H.Lee kongyeeku@163.com * @version  1.0 */public interface Peppery{String style();}



/** * Description: * <br/>网站: <a href="http://www.crazyit.org">疯狂Java联盟</a>  * <br/>Copyright (C), 2001-2012, Yeeku.H.Lee * <br/>This program is protected by copyright laws. * <br/>Program Name: * <br/>Date: * @author  Yeeku.H.Lee kongyeeku@163.com * @version  1.0 */public class PlainStyle implements Peppery{//实现"不辣"风格的方法public String style(){return "味道清淡,很养胃...";}}



/** * Description: * <br/>网站: <a href="http://www.crazyit.org">疯狂Java联盟</a>  * <br/>Copyright (C), 2001-2012, Yeeku.H.Lee * <br/>This program is protected by copyright laws. * <br/>Program Name: * <br/>Date: * @author  Yeeku.H.Lee kongyeeku@163.com * @version  1.0 */public class PepperySytle implements Peppery{//实现"辣味"风格的方法public String style(){return "辣味很重,很过瘾...";}}



/** * Description: * <br/>网站: <a href="http://www.crazyit.org">疯狂Java联盟</a>  * <br/>Copyright (C), 2001-2012, Yeeku.H.Lee * <br/>This program is protected by copyright laws. * <br/>Program Name: * <br/>Date: * @author  Yeeku.H.Lee kongyeeku@163.com * @version  1.0 */public abstract class AbstractNoodle{//组合一个Peppery变量,用于将该维度的变化独立出来protected Peppery style;//每份Noodle必须组合一个Peppery对象public AbstractNoodle(Peppery style){this.style = style;}public abstract void eat();}



/** * Description: * <br/>网站: <a href="http://www.crazyit.org">疯狂Java联盟</a>  * <br/>Copyright (C), 2001-2012, Yeeku.H.Lee * <br/>This program is protected by copyright laws. * <br/>Program Name: * <br/>Date: * @author  Yeeku.H.Lee kongyeeku@163.com * @version  1.0 */public class PorkyNoodle extends AbstractNoodle{public PorkyNoodle(Peppery style){super(style);}//实现eat()抽象方法public void eat(){System.out.println("这是一碗稍嫌油腻的猪肉面条。"+ super.style.style());}}



/** * Description: * <br/>网站: <a href="http://www.crazyit.org">疯狂Java联盟</a>  * <br/>Copyright (C), 2001-2012, Yeeku.H.Lee * <br/>This program is protected by copyright laws. * <br/>Program Name: * <br/>Date: * @author  Yeeku.H.Lee kongyeeku@163.com * @version  1.0 */public class BeefNoodle extends AbstractNoodle{public BeefNoodle(Peppery style){super(style);}//实现eat()抽象方法public void eat(){System.out.println("这是一碗美味的牛肉面条。"+ super.style.style());}}




/** * Description: * <br/>网站: <a href="http://www.crazyit.org">疯狂Java联盟</a>  * <br/>Copyright (C), 2001-2012, Yeeku.H.Lee * <br/>This program is protected by copyright laws. * <br/>Program Name: * <br/>Date: * @author  Yeeku.H.Lee kongyeeku@163.com * @version  1.0 */public class BeefNoodle extends AbstractNoodle{public BeefNoodle(Peppery style){super(style);}//实现eat()抽象方法public void eat(){System.out.println("这是一碗美味的牛肉面条。"+ super.style.style());}}