閱讀699 返回首頁    go 阿裏雲 go 技術社區[雲棲]


【橋接模式】【辣椒、不辣 牛肉、豬肉 麵 組合】

/**
 * Description:
 * <br/>網站: <a href="https://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="https://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="https://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="https://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="https://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="https://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="https://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());
	}
}









最後更新:2017-04-04 07:03:36

  上一篇:go initWithFormat 和stringWithFormat的區別
  下一篇:go 解決tomcat引入spring容器出錯