关闭

Abstract Factory

102人阅读 评论(0) 收藏 举报

public abstract class AbsConcertFactory {
    public abstract IMusic createMusic();
   
    public abstract IMusicBox createMusicBox();
}

 

 

 

public class LatinConcertFactory extends AbsConcertFactory {

    /* (non-Javadoc)
     * @see com.sean.designpattern.demo.music.AbsConcertFactory#createMusic()
     */
    @Override
    public IMusic createMusic() {
        return new LatinMusic();
    }

    /* (non-Javadoc)
     * @see com.sean.designpattern.demo.music.AbsConcertFactory#createMusicBox()
     */
    @Override
    public IMusicBox createMusicBox() {
        return new ViolinBox();
    }

}

 

 

public class PopConcertFactory extends AbsConcertFactory {
    /* (non-Javadoc)
     * @see com.sean.designpattern.demo.music.AbsConcertFactory#createMusic()
     */
    @Override
    public IMusic createMusic() {
        return new PopMusic();
    }

    /* (non-Javadoc)
     * @see com.sean.designpattern.demo.music.AbsConcertFactory#createMusicBox()
     */
    @Override
    public IMusicBox createMusicBox() {
        return new PianoBox();
    }
}

 

0
0

查看评论
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
    个人资料
    • 访问:7405次
    • 积分:268
    • 等级:
    • 排名:千里之外
    • 原创:21篇
    • 转载:2篇
    • 译文:0篇
    • 评论:0条
    文章分类