java设计模式进阶_prototype

这里写图片描述

//
//
//  Generated by StarUML(tm) Java Add-In
//
//  @ Project : Untitled
//  @ File Name : HeroFactory.java
//  @ Date : 2016/8/22
//  @ Author : wuchao
//
//




public interface HeroFactory {
    public Mage createMage();
    public Warlord createWarlord();
    public Beast createBeast();
}

//
//
//  Generated by StarUML(tm) Java Add-In
//
//  @ Project : Untitled
//  @ File Name : HeroFactoryImpl.java
//  @ Date : 2016/8/22
//  @ Author : wuchao
//
//




public class HeroFactoryImpl implements HeroFactory {

    public Mage mage;
    public Warlord warlord;
    public Beast beast;

    public HeroFactoryImpl(Mage mage, Warlord warlord, Beast beast) {
        this.mage = mage;
        this.warlord = warlord;
        this.beast = beast;
    }

    public Mage createMage() {
        try {
            return mage.clone();
        } catch (CloneNotSupportedException e) {
            return null;
        }
    }

    public Warlord createWarlord() {
        try {
            return warlord.clone();
        } catch (CloneNotSupportedException e) {
            return null;
        }
    }

    public Beast createBeast() {
        try {
            return beast.clone();
        } catch (CloneNotSupportedException e) {
            return null;
        }
    }

}
//
//
//  Generated by StarUML(tm) Java Add-In
//
//  @ Project : Untitled
//  @ File Name : Prototype.java
//  @ Date : 2016/8/22
//  @ Author : wuchao
//
//




public abstract class Prototype {
    public abstract Object clone() throws CloneNotSupportedException;
}
//
//
//  Generated by StarUML(tm) Java Add-In
//
//  @ Project : Untitled
//  @ File Name : Beast.java
//  @ Date : 2016/8/22
//  @ Author : wuchao
//
//




public abstract class Beast extends Prototype {
    public abstract Beast clone() throws CloneNotSupportedException;
}

//
//
//  Generated by StarUML(tm) Java Add-In
//
//  @ Project : Untitled
//  @ File Name : Mage.java
//  @ Date : 2016/8/22
//  @ Author : wuchao
//
//




public abstract class Mage extends Prototype {
    public abstract Mage clone() throws CloneNotSupportedException;
}

//
//
//  Generated by StarUML(tm) Java Add-In
//
//  @ Project : Untitled
//  @ File Name : Warlord.java
//  @ Date : 2016/8/22
//  @ Author : wuchao
//
//




public abstract class Warlord extends Prototype {
    public abstract Warlord clone() throws CloneNotSupportedException;
}

//
//
//  Generated by StarUML(tm) Java Add-In
//
//  @ Project : Untitled
//  @ File Name : OrcWarlorc.java
//  @ Date : 2016/8/22
//  @ Author : wuchao
//
//




public class OrcWarlord extends Warlord {

    private OrcWarlord orcWarlord;

    public OrcWarlord() {

    }

    public OrcWarlord(OrcWarlord orcWarlord) {
        this.orcWarlord = orcWarlord;
    }

    public String toString() {
        return "Orcish warlord";
    }

    @Override
    public Warlord clone() throws CloneNotSupportedException {
        return new OrcWarlord(this);
    }

}

//
//
//  Generated by StarUML(tm) Java Add-In
//
//  @ Project : Untitled
//  @ File Name : OrcMage.java
//  @ Date : 2016/8/22
//  @ Author : wuchao
//
//




public class OrcMage extends Mage {
    private OrcMage orcMage;

    public OrcMage() {

    }

    public OrcMage(OrcMage orcMage) {
        this.orcMage = orcMage;
    }

    public String toString() {
        return "Orcish mage";
    }

    @Override
    public Mage clone() throws CloneNotSupportedException {
        return new OrcMage(this);
    }

}


//
//
//  Generated by StarUML(tm) Java Add-In
//
//  @ Project : Untitled
//  @ File Name : OrcBeast.java
//  @ Date : 2016/8/22
//  @ Author : wuchao
//
//




public class OrcBeast extends Beast {
    private OrcBeast orcBeast;

    public OrcBeast() {

    }

    public OrcBeast(OrcBeast orcBeast) {
        this.orcBeast = orcBeast;
    }

    public String toString() {
        return "Orcish wolf";
    }

    @Override
    public Beast clone() throws CloneNotSupportedException {
        return new OrcBeast(this);
    }

}

//
//
//  Generated by StarUML(tm) Java Add-In
//
//  @ Project : Untitled
//  @ File Name : ElfWarlord.java
//  @ Date : 2016/8/22
//  @ Author : wuchao
//
//




public class ElfWarlord extends Warlord {

    private ElfWarlord elfWarlord;

    public ElfWarlord() {

    }

    public ElfWarlord(ElfWarlord elfWarlord) {
        this.elfWarlord = elfWarlord;
    }

    public String toString() {
        return "Elven warlord";
    }

    @Override
    public Warlord clone() throws CloneNotSupportedException {
        return new ElfWarlord(this);
    }

}
//
//
//  Generated by StarUML(tm) Java Add-In
//
//  @ Project : Untitled
//  @ File Name : ElfMage.java
//  @ Date : 2016/8/22
//  @ Author : wuchao
//
//




public class ElfMage extends Mage {
    private ElfMage elfMage = null;

    public ElfMage() {

    }

    public ElfMage(ElfMage elfMage) {
        this.elfMage = elfMage;
    }

    @Override
    public Mage clone() throws CloneNotSupportedException {
        return new ElfMage(this);
    }

    public String toString() {
        return "Elven mage";
    }
}


//
//
//  Generated by StarUML(tm) Java Add-In
//
//  @ Project : Untitled
//  @ File Name : ElfBeast.java
//  @ Date : 2016/8/22
//  @ Author : wuchao
//
//




public class ElfBeast extends Beast {
    private ElfBeast elfBeast = null;

    public ElfBeast() {

    }

    public ElfBeast(ElfBeast elfBeast) {
        this.elfBeast = elfBeast;
    }

    @Override
    public Beast clone() throws CloneNotSupportedException {
        return new ElfBeast(this);
    }

    @Override
    public String toString() {
        return "Elven eagle";
    }
}






评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值