原型模式

1 单例模式/原型模式

2 浅克隆 VS深克隆

3 原型模式的应用

原型模式:创建型设计模式,关注对象的创建,通过clone的方式创建对象

享元模式:行为型设计模式,做的对象的共享

单例模式:保证进程中该对象只有一个实例

单例模式:

public class StudentSingleton{

private 

private static StudentSingleton _student=null;

public static StudentSingleton(){

  _student=new StudentSingleton();

}

private StudentSingleton(){}

public StudentSingleton CreateInstance(){

  return _student;

}

}

原型模式

public class StudentPrototype{

private 

private static StudentPrototype _student=null;

public static StudentPrototype(){

  _student=new StudentPrototype();

}

private StudentPrototype(){}

public StudentPrototype CreateInstance(){

StudentPrototype student=(StudentPrototype) _student.meberwiseclone();//不走构造函数,构造对象的另外一个方式, 浅克隆

return student;

}

}

 

posted on 2017-11-21 11:11  wendy wang  阅读(45)  评论(0)    收藏  举报

导航