kwj

走越远,路越艰!

常用链接

统计

最新评论

工厂方法模式

public interface FruitGardener  //园丁接口
{
    public Fruit factory();
}

public class AppleGardener implements FruitGardener
{
    public Fruit factory()
    {
        return new Apple();
    }
}

public class GrapeGardener implements FruitGardener
{
    public Fruit factory()
    {
        return new Grape();
    }
}

public interface fruit()  //水果接口
{
    void grow();
    void harvest();
    void plant();
}

public class Apple implements Fruit
{
    private int treeAge;
    public void grow(){}
    public void harvest(){}
    public void plant(){}
}
public class Grape implements Fruit
{
    private boolean seedless;
    public void grow(){}
    public void harvest(){}
    public void plant(){}
}

所涉及角色:抽象工厂角色,具体工厂角色,抽象产品角色,具体产品角色。


posted on 2008-01-23 10:56 木剑 阅读(132) 评论(0)  编辑  收藏 所属分类: 设计模式


只有注册用户登录后才能发表评论。


网站导航: