static void Main(string[] args) { // Create two instances and clone each Telo T1 = new Telo(10, "ggg"); System s1 = new ConcretePrototype1(T1); System c1 = s1.Clone(); c1.SsS.DLINA = 8; c1.SsS.NAME = "rrrrrr"; Console.WriteLine("Dlina: {0} Name: {1}", c1.SsS.DLINA, c1.SsS.NAME); Console.WriteLine("Dlina: {0} Name: {1}", s1.SsS.DLINA, s1.SsS.NAME); Telo T2 = new Telo(50, "hohoho"); System s2 = new ConcretePrototype2(T2); System c2 = s2.Clone(); c2.SsS.DLINA = 25; c2.SsS.NAME = "zozozo"; Console.WriteLine("Dlina: {0} Name: {1}", c2.SsS.DLINA, c2.SsS.NAME); Console.WriteLine("Dlina: {0} Name: {1}", s2.SsS.DLINA, s2.SsS.NAME); // Wait for user Console.Read(); }
static void Main(string[] args) { Prototype prototype = new ConcretePrototype1(1); Prototype clone = prototype.Clone(); prototype = new ConcretePrototype2(2); clone = prototype.Clone(); }
static void Main() { // Create two instances and clone each Prototype prototype1 = new ConcretePrototype1("I"); Prototype clonedPrototype1 = prototype1.Clone(); Console.WriteLine ("Cloned: {0}", clonedPrototype1 .Id); Prototype prototype2 = new ConcretePrototype2("II"); Prototype clonedPrototype2 = prototype2.Clone(); Console.WriteLine ("Cloned: {0}", clonedPrototype2 .Id); }
static void Main(string[] args) { Prototype prototype = null; Prototype clone = null; prototype = new ConcretePrototype1(1); clone = prototype.Clone(); prototype = new ConcretePrototype2(2); clone = prototype.Clone(); }
static void Main() { Prototype prototype = null; Prototype original = null; prototype = new ConcretePrototype1(1); original = prototype.Clone(); prototype = new ConcretePrototype2(2); original = prototype.Clone(); }
static void Main(string[] args) { Prototype prototype; Prototype original; prototype = new ConcretePrototype1(1); original = prototype.Clone(); prototype = new ConcretePrototype2(2); original = prototype.Clone(); }
static void Main(string[] args) { Prototype prototype = new ConcretePrototype1(10, 15, 23); Prototype clone = prototype.Clone(); prototype = new ConcretePrototype2(14, 5, 50); clone = prototype.Clone(); prototype = new Triangle(10, 14, 50);; clone = prototype.Clone(); }
private static void Main() { ConcretePrototype1 p1 = new ConcretePrototype1("This is Concrete 1"); ConcretePrototype1 c1 = (ConcretePrototype1)p1.Clone(); Console.WriteLine("Cloned: {0}", c1.Id); ConcretePrototype2 p2 = new ConcretePrototype2("This is Concrete 2"); ConcretePrototype2 c2 = (ConcretePrototype2)p2.Clone(); Console.WriteLine("Cloned: {0}", c2.Id); Console.ReadLine(); }
static void Main(string[] args) { ConcretePrototype1 p1 = new ConcretePrototype1("1"); ConcretePrototype1 c1 = (ConcretePrototype1)p1.Clone(); Console.WriteLine("Cloned: {0}", c1.Id); ConcretePrototype2 p2 = new ConcretePrototype2("2"); ConcretePrototype2 c2 = (ConcretePrototype2)p2.Clone(); Console.WriteLine("Cloned: {0}", c2.Id); Console.ReadKey(); }
static void Main(string[] args) { ConcretePrototype1 concretePrototype1 = new ConcretePrototype1("I"); ConcretePrototype1 c1 = (ConcretePrototype1)concretePrototype1.Clone(); ConcretePrototype2 concretePrototype2 = new ConcretePrototype2("II"); ConcretePrototype2 c2 = (ConcretePrototype2)concretePrototype2.Clone(); Console.WriteLine("Cloned: " + c1.Id); Console.WriteLine("Cloned: " + c2.Id); Console.ReadKey(); }
static void Main() { Prototype prototype1 = new ConcretePrototype1("I"); Prototype clonedPrototype1 = prototype1.Clone(); Console.WriteLine("Cloned: {0}", clonedPrototype1.Id); Prototype prototype2 = new ConcretePrototype2("II"); Prototype clonedPrototype2 = prototype2.Clone(); Console.WriteLine("Cloned: {0}", clonedPrototype2.Id); }
static void Main(string[] args) { ConcretePrototype1 p1 = new ConcretePrototype1("I"); ConcretePrototype1 c1 = (ConcretePrototype1)p1.Clone(); Console.WriteLine("Cloned: {0}", c1.Id); ConcretePrototype2 p2 = new ConcretePrototype2("II"); ConcretePrototype2 c2 = (ConcretePrototype2)p2.Clone(); Console.WriteLine("Cloned: {0}", c2.Id); Console.ReadKey(); }
/// <summary> /// Entry point into console application. /// </summary> static void Main() { // Create two instances and clone each ConcretePrototype1 p1 = new ConcretePrototype1("I"); ConcretePrototype1 c1 = (ConcretePrototype1)p1.Clone(); Console.WriteLine("Cloned: {0}", c1.Id); ConcretePrototype2 p2 = new ConcretePrototype2("II"); ConcretePrototype2 c2 = (ConcretePrototype2)p2.Clone(); Console.WriteLine("Cloned: {0}", c2.Id); }
static void Main(string[] args) { //Создания двух экземпляров и клонирование их. ConcretePrototype1 p1 = new ConcretePrototype1("1"); ConcretePrototype1 c1 = p1.Clone() as ConcretePrototype1; Console.WriteLine("Clonned: {0}", c1.Id); ConcretePrototype2 p2 = new ConcretePrototype2("2"); ConcretePrototype2 c2 = p2.Clone() as ConcretePrototype2; Console.WriteLine("Clonned: {0}", c2.Id); }
static void Main(string[] args) { ConcretePrototype1 p1 = new ConcretePrototype1("A"); ConcretePrototype2 p2 = new ConcretePrototype2("B"); ConcretePrototype1 pc1 = (ConcretePrototype1)p1.Clone(); ConcretePrototype2 pc2 = (ConcretePrototype2)p2.Clone(); Console.WriteLine("Cloned : " + pc1.Id); Console.WriteLine("Cloned : " + pc2.Id); Console.ReadKey(); }
static void Main(string[] args) { Prototype prototype = null; Prototype clone = null; prototype = new ConcretePrototype1(1); clone = prototype.Clone(); Console.WriteLine(clone.Id); prototype = new ConcretePrototype2(2); clone = prototype.Clone(); Console.WriteLine(clone.Id); Console.ReadKey(); }
static void Main() { // Create two instances and clone each Prototype prototype1 = new ConcretePrototype1("I"); Prototype clonedPrototype1 = prototype1.Clone(); Console.WriteLine("Cloned: {0}", clonedPrototype1.Id); Prototype prototype2 = new ConcretePrototype2("II"); Prototype clonedPrototype2 = prototype2.Clone(); Console.WriteLine("Cloned: {0}", clonedPrototype2.Id); }
/// <summary> /// Entry point into console application. /// </summary> static void Main() { // Create two instances and clone each ConcretePrototype1 p1 = new ConcretePrototype1("I"); ConcretePrototype1 c1 = (ConcretePrototype1)p1.Clone(); Console.WriteLine("Cloned: {0}", c1.Id); ConcretePrototype2 p2 = new ConcretePrototype2("II"); ConcretePrototype2 c2 = (ConcretePrototype2)p2.Clone(); Console.WriteLine("Cloned: {0}", c2.Id); // Wait for user Console.ReadKey(); }
static void Main(string[] args) { ConcretePrototype1 p1 = new ConcretePrototype1("1610207"); ConcretePrototype1 copy1 = (ConcretePrototype1)p1.Clone(); Console.WriteLine("Cloned: {0}", copy1.ID); ConcretePrototype2 p2 = new ConcretePrototype2("La Quoc Thang"); ConcretePrototype2 copy2 = (ConcretePrototype2)p2.Clone(); Console.WriteLine("Cloned: {0}", copy2.ID); Console.ReadKey(); }
static void Main() { ConcretePrototype1 p1 = new ConcretePrototype1("I"), c1 = (ConcretePrototype1)p1.Clone(); Console.WriteLine("Cloned: {0}", c1.Id); ConcretePrototype2 p2 = new ConcretePrototype2("II"), c2 = (ConcretePrototype2)p2.Clone(); Console.WriteLine("Cloned: {0}", c2.Id); }
static void Main(string[] args) { ConcretePrototype1 p1 = new ConcretePrototype1("p1"); ConcretePrototype1 clonedP1 = (ConcretePrototype1)p1.Clone(); Console.WriteLine(clonedP1.Id); Console.WriteLine(p1.Equals(clonedP1)); ConcretePrototype2 p2 = new ConcretePrototype2("p2"); ConcretePrototype2 clonedP2 = (ConcretePrototype2)p2.Clone(); Console.WriteLine(clonedP2.Id); Console.WriteLine(p2.Equals(clonedP2)); Console.Read(); }
static void Main() { // Create two instances and clone each var p1 = new ConcretePrototype1("I"); var c1 = (ConcretePrototype1)p1.Clone(); Console.WriteLine("Cloned: {0}", c1.Id); var p2 = new ConcretePrototype2("II"); var c2 = (ConcretePrototype2)p2.Clone(); Console.WriteLine("Cloned: {0}", c2.Id); // Wait for user Console.Read(); }
static void Main() { // Создание двух экземпляров и клонирование их. ConcretePrototype1 p1 = new ConcretePrototype1("1"); ConcretePrototype1 c1 = p1.Clone() as ConcretePrototype1; Console.WriteLine("Cloned: {0}", c1.Id); ConcretePrototype2 p2 = new ConcretePrototype2("2"); ConcretePrototype2 c2 = p2.Clone() as ConcretePrototype2; Console.WriteLine("Cloned: {0}", c2.Id); // Задержка. Console.ReadKey(); }
public static void Run() { Console.WriteLine("This structural code demonstrates the Prototype pattern in which new objects are created by copying pre-existing objects (prototypes) of the same class."); ConcretePrototype1 p1 = new ConcretePrototype1("I"); ConcretePrototype1 c1 = (ConcretePrototype1)p1.Clone(); Console.WriteLine("Cloned: {0}", c1.Id); ConcretePrototype2 p2 = new ConcretePrototype2("II"); ConcretePrototype2 c2 = (ConcretePrototype2)p2.Clone(); Console.WriteLine("Cloned: {0}", c2.Id); /* * Cloned: I * Cloned: II */ }
static void Main(string[] args) { // Create two instances and clone each ConcretePrototype1 p1 = new ConcretePrototype1("I"); ConcretePrototype1 c1 = (ConcretePrototype1)p1.Clone(); Console.WriteLine("Cloned: {0}", c1.Id); ConcretePrototype2 p2 = new ConcretePrototype2("II"); ConcretePrototype2 c2 = (ConcretePrototype2)p2.Clone(); Console.WriteLine("Cloned: {0}", c2.Id); // Wait for user Console.ReadKey(); }
static void Main() { // Create two instances and clone each ConcretePrototype1 p1 = new ConcretePrototype1("I"); ConcretePrototype1 c1 = (ConcretePrototype1)p1.Clone(); MessageBox.Show("Cloned: " + c1.Id); ConcretePrototype2 p2 = new ConcretePrototype2("II"); ConcretePrototype2 c2 = (ConcretePrototype2)p2.Clone(); MessageBox.Show("Cloned: " + c2.Id); //Application.EnableVisualStyles(); //Application.SetCompatibleTextRenderingDefault(false); //Application.Run(new Form1()); }
static void Main1(string[] args) { // Create two instances and clone each ConcretePrototype1 p1 = new ConcretePrototype1("I"); Console.WriteLine("Cloned: {0}", p1.Id); ConcretePrototype1 client1 = (ConcretePrototype1)p1.Clone(); Console.WriteLine("Cloned: {0}", client1.Id); ConcretePrototype2 p2 = new ConcretePrototype2("II"); Prototype client2 = p2.Clone(); Console.WriteLine("Cloned: {0}", client2.Id); Console.ReadKey(); }
static void Main(string[] args) { var prototype = new ConcretePrototype1 { Property1 = "A", Property2 = "B", PrototypeDetails = new PrototypeDetails { Details = "prototype details" } }; var NewObject = prototype.Clone() as ConcretePrototype1; NewObject.PrototypeDetails.Details = "New details for 'NewObject'"; Console.WriteLine(prototype); Console.WriteLine(NewObject); var prototype2 = new ConcretePrototype2 { Property1 = "X", Property2 = "Y", OtherProperty = "Z", PrototypeDetails = new PrototypeDetails { Details = "prototype2 details" } }; var NewObject2 = prototype2.Clone() as ConcretePrototype2; NewObject2.PrototypeDetails.Details = "New details for 'NewObject2'"; Console.WriteLine(prototype2); Console.WriteLine(NewObject2); Console.ReadKey(); }
static void Main(string[] args) { #region 结构实现 // Create two instances and clone each ConcretePrototype1 p1 = new ConcretePrototype1("I"); ConcretePrototype1 c1 = (ConcretePrototype1)p1.Clone(); Console.WriteLine("Cloned: {0}", c1.Id); ConcretePrototype2 p2 = new ConcretePrototype2("II"); ConcretePrototype2 c2 = (ConcretePrototype2)p2.Clone(); Console.WriteLine("Cloned: {0}", c2.Id); #endregion Console.WriteLine("******************************"); #region 实践应用 ColorManager colormanager = new ColorManager(); // Initialize with standard colors colormanager["red"] = new Color(255, 0, 0); colormanager["green"] = new Color(0, 255, 0); colormanager["blue"] = new Color(0, 0, 255); // User adds personalized colors colormanager["angry"] = new Color(255, 54, 0); colormanager["peace"] = new Color(128, 211, 128); colormanager["flame"] = new Color(211, 34, 20); // User clones selected colors Color color1 = colormanager["red"].Clone() as Color; Color color2 = colormanager["peace"].Clone() as Color; Color color3 = colormanager["flame"].Clone() as Color; #endregion Console.ReadKey(); }
static void Main(string[] args) { ConcretePrototype1 p1 = new ConcretePrototype1("Prototype I"); ConcretePrototype1 c1 = (ConcretePrototype1)p1.Clone(); Console.WriteLine($"Cloned c1\n{GetDetails(c1)}"); Console.WriteLine($"From p1\n{GetDetails(p1)}"); ConcretePrototype2 p2 = new ConcretePrototype2("Prototype II"); ConcretePrototype2 c2 = (ConcretePrototype2)p2.Clone(); Console.WriteLine($"Cloned c2\n{GetDetails(c2)}"); Console.WriteLine($"From p2\n{GetDetails(p2)}"); // Output: // Cloned c1 // ID: Prototype I hashcode: 58225482 // From p1 // ID: Prototype I hashcode: 54267293 // Cloned c2 // ID: Prototype II hashcode: 18643596 // From p2 // ID: Prototype II hashcode: 33574638 }