/** * 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()); } }
时间: 2024-11-30 07:00:06