A股上市公司传智教育(股票代码 003032)旗下技术交流社区北京昌平校区

 找回密码
 加入黑马

QQ登录

只需一步,快速开始

代码最好简单!!

2 个回复

倒序浏览
字体类型的基类:

    public class FontBase
    {
        private List<string> font = new List<string>();

        private string fontName;
        public FontBase(string name)
        {
            this.fontName = name;
        }

        public FontBase AddFont(string font)
        {
            this.font.Add(font);
            return this;
        }
        public virtual string FontName
        {
            get
            {
                return this.fontName;
            }
        }
    }

    具体的文字类型类:

    public class ChineseFont : FontBase
    {
        public ChineseFont()
            : base("ChineseFont")
        {
            base.AddFont("ChineseFont");
        }
    }

    public class EnglishFont : FontBase
    {
        public EnglishFont()
            : base("EnglishFont")
        {
            base.AddFont("EnglishFont");
        }
    }

具体的创建工厂类:

    public class FontFactory
    {
        private  Dictionary<string, FontBase> fonts = new Dictionary<string, FontBase>();

        public  FontBase Create(string name)
        {
            FontBase fontBase = fonts[name];
            if (fontBase != null)
                return fontBase;

            fontBase = (FontBase)Activator.CreateInstance(Type.GetType(name));

            return fontBase;
        }
    }

评分

参与人数 1技术分 +1 收起 理由
奋斗的青春 + 1 赞一个!

查看全部评分

回复 使用道具 举报
实例如下:
public class demo{
        public static void main(String[] args){
                Integer i1=34;//自动装箱
                Integer i2=34;
                Integer i3=34;
                Integer i4=34;
                System.out.println(i1==i2);//结果为true,说明i1,i2共享了数据
                System.out.println(i2==i3);//true
                System.out.println(i3==i4);//true
                System.out.println(i1==i3);//true
        }       
       
}

评分

参与人数 1技术分 +1 收起 理由
奋斗的青春 + 1 赞一个!

查看全部评分

回复 使用道具 举报
您需要登录后才可以回帖 登录 | 加入黑马