File tree Expand file tree Collapse file tree 4 files changed +23
-3
lines changed
Creational/ProtypePattern/src/io/csie/chris Expand file tree Collapse file tree 4 files changed +23
-3
lines changed Original file line number Diff line number Diff line change 1+ package io .csie .chris ;
2+
3+ import io .csie .chris .prototype .Dog ;
4+ import io .csie .chris .prototype .Person ;
5+
16public class Main {
7+
28 public static void main (String args []) {
9+
310 Person person1 = new Person ("Chris" , "1234567" , 25 );
411 System .out .println (person1 .displayInfo ());
512
Original file line number Diff line number Diff line change 1+ package io .csie .chris .prototype ;
2+
3+ import io .csie .chris .prototype .common .IPrototype ;
4+
15public class Dog implements IPrototype {
6+
27 private String sound ;
38
49 public Dog (String sound ) {
510 this .sound = sound ;
611 }
712
8- // Make a copy from IPrototype
13+ // Make a copy from io.csie.chris.prototype.common. IPrototype
914 @ Override
1015 public IPrototype doClone () {
1116 return new Dog (sound );
Original file line number Diff line number Diff line change 1+ package io .csie .chris .prototype ;
2+
3+ import io .csie .chris .prototype .common .IPrototype ;
4+
15public class Person implements IPrototype {
6+
27 private String name ;
38 private String id ;
49 private int age ;
@@ -21,7 +26,7 @@ public void setAge(int age) {
2126 this .age = age ;
2227 }
2328
24- // Make a copy from IPrototype
29+ // Make a copy from io.csie.chris.prototype.common. IPrototype
2530 @ Override
2631 public IPrototype doClone () {
2732 return new Person (name , id , age );
Original file line number Diff line number Diff line change 1+ package io .csie .chris .prototype .common ;
2+
13public interface IPrototype {
4+
25 // Create a public method, which can clone whole instance
3- public IPrototype doClone ();
6+ IPrototype doClone ();
47}
You can’t perform that action at this time.
0 commit comments