Skip to content

Commit e6eed56

Browse files
author
chrish
committed
Refactoring PrototypePattern.
1 parent ca5ed35 commit e6eed56

File tree

4 files changed

+23
-3
lines changed

4 files changed

+23
-3
lines changed

CreationalDesignPattern/PrototypePattern/Java/PrototypeDemo/Main.java renamed to Creational/ProtypePattern/src/io/csie/chris/Main.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
1+
package io.csie.chris;
2+
3+
import io.csie.chris.prototype.Dog;
4+
import io.csie.chris.prototype.Person;
5+
16
public 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

CreationalDesignPattern/PrototypePattern/Java/PrototypeDemo/Dog.java renamed to Creational/ProtypePattern/src/io/csie/chris/prototype/Dog.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,16 @@
1+
package io.csie.chris.prototype;
2+
3+
import io.csie.chris.prototype.common.IPrototype;
4+
15
public 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);

CreationalDesignPattern/PrototypePattern/Java/PrototypeDemo/Person.java renamed to Creational/ProtypePattern/src/io/csie/chris/prototype/Person.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
1+
package io.csie.chris.prototype;
2+
3+
import io.csie.chris.prototype.common.IPrototype;
4+
15
public 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);

CreationalDesignPattern/PrototypePattern/Java/PrototypeDemo/IPrototype.java renamed to Creational/ProtypePattern/src/io/csie/chris/prototype/common/IPrototype.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1+
package io.csie.chris.prototype.common;
2+
13
public interface IPrototype {
4+
25
// Create a public method, which can clone whole instance
3-
public IPrototype doClone();
6+
IPrototype doClone();
47
}

0 commit comments

Comments
 (0)