192.168.1.41_20200907-方栋泽

一、问题

多例模式:


/**
 * 1、将所有构造私有化
 * 2、创建当前类的有限个实例
 * 3、提供一个类方法用来获取该类的实例
 */
public class Season {
    
    private static final Season SPRING = new Season( "春季" , "春暖花开" ) ;
    private static final Season SUMMER = new Season( "夏季" , "热死你个鳖孙儿" ) ;
    private static final Season AUTUMN = new Season( "秋季" , "秋高气爽" ) ;
    private static final Season WINTER = new Season( "冬季" , "冻死你个哈怂" ) ;

    private String name; // 季节名称
    private String feature; // 季节特征
    
    private Season( String name , String feature ) {
        this.name = name ;
        this.feature = feature ;
    }
    
    public static Season getInstance( int index ) {
        switch (index) {
            case 1: return SPRING ;
            case 2: return SUMMER ;
            case 3: return AUTUMN ;
            case 4: return WINTER ;
            default: return null ;
        }
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getFeature() {
        return feature;
    }

    public void setFeature(String feature) {
        this.feature = feature;
    }

}

多例模式也要记下来,老师会考

二、吐槽

今天开始学集合,一下子代码量就多了,这是新的生活的开始吗。今天教室好热,把我们这一片的同学都整瞌睡了好多。感觉佟姐和她的那个猴哥是班级里的开心果,哈哈哈!!!

标签

© 2021 成都云创动力科技有限公司 蜀ICP备20006351号-1