X Tutup
Skip to content

Commit 0db6581

Browse files
committed
iluwatar#107 Improve JavaDoc for Prototype
1 parent 8fb0ec1 commit 0db6581

File tree

12 files changed

+267
-208
lines changed

12 files changed

+267
-208
lines changed
Lines changed: 40 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,40 @@
1-
package com.iluwatar.prototype;
2-
3-
/**
4-
*
5-
* In Prototype we have a factory class (HeroFactoryImpl) producing objects by
6-
* cloning existing ones. In this example the factory's prototype objects are
7-
* given as constructor parameters.
8-
*
9-
*/
10-
public class App {
11-
12-
public static void main(String[] args) {
13-
HeroFactory factory;
14-
Mage mage;
15-
Warlord warlord;
16-
Beast beast;
17-
18-
factory = new HeroFactoryImpl(new ElfMage(), new ElfWarlord(),
19-
new ElfBeast());
20-
mage = factory.createMage();
21-
warlord = factory.createWarlord();
22-
beast = factory.createBeast();
23-
System.out.println(mage);
24-
System.out.println(warlord);
25-
System.out.println(beast);
26-
27-
factory = new HeroFactoryImpl(new OrcMage(), new OrcWarlord(),
28-
new OrcBeast());
29-
mage = factory.createMage();
30-
warlord = factory.createWarlord();
31-
beast = factory.createBeast();
32-
System.out.println(mage);
33-
System.out.println(warlord);
34-
System.out.println(beast);
35-
}
36-
}
1+
package com.iluwatar.prototype;
2+
3+
/**
4+
*
5+
* In Prototype we have a factory class ({@link HeroFactoryImpl}) producing objects by
6+
* cloning the existing ones. In this example the factory's prototype objects are
7+
* given as constructor parameters.
8+
*
9+
*/
10+
public class App {
11+
12+
/**
13+
* Program entry point
14+
* @param args command line args
15+
*/
16+
public static void main(String[] args) {
17+
HeroFactory factory;
18+
Mage mage;
19+
Warlord warlord;
20+
Beast beast;
21+
22+
factory = new HeroFactoryImpl(new ElfMage(), new ElfWarlord(),
23+
new ElfBeast());
24+
mage = factory.createMage();
25+
warlord = factory.createWarlord();
26+
beast = factory.createBeast();
27+
System.out.println(mage);
28+
System.out.println(warlord);
29+
System.out.println(beast);
30+
31+
factory = new HeroFactoryImpl(new OrcMage(), new OrcWarlord(),
32+
new OrcBeast());
33+
mage = factory.createMage();
34+
warlord = factory.createWarlord();
35+
beast = factory.createBeast();
36+
System.out.println(mage);
37+
System.out.println(warlord);
38+
System.out.println(beast);
39+
}
40+
}
Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,13 @@
1-
package com.iluwatar.prototype;
2-
3-
public abstract class Beast extends Prototype {
4-
5-
@Override
6-
public abstract Beast clone() throws CloneNotSupportedException;
7-
8-
}
1+
package com.iluwatar.prototype;
2+
3+
/**
4+
*
5+
* Beast
6+
*
7+
*/
8+
public abstract class Beast extends Prototype {
9+
10+
@Override
11+
public abstract Beast clone() throws CloneNotSupportedException;
12+
13+
}
Lines changed: 26 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,26 @@
1-
package com.iluwatar.prototype;
2-
3-
public class ElfBeast extends Beast {
4-
5-
public ElfBeast() {
6-
}
7-
8-
public ElfBeast(ElfBeast beast) {
9-
}
10-
11-
@Override
12-
public Beast clone() throws CloneNotSupportedException {
13-
return new ElfBeast(this);
14-
}
15-
16-
@Override
17-
public String toString() {
18-
return "Elven eagle";
19-
}
20-
21-
}
1+
package com.iluwatar.prototype;
2+
3+
/**
4+
*
5+
* ElfBeast
6+
*
7+
*/
8+
public class ElfBeast extends Beast {
9+
10+
public ElfBeast() {
11+
}
12+
13+
public ElfBeast(ElfBeast beast) {
14+
}
15+
16+
@Override
17+
public Beast clone() throws CloneNotSupportedException {
18+
return new ElfBeast(this);
19+
}
20+
21+
@Override
22+
public String toString() {
23+
return "Elven eagle";
24+
}
25+
26+
}
Lines changed: 26 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,26 @@
1-
package com.iluwatar.prototype;
2-
3-
public class ElfMage extends Mage {
4-
5-
public ElfMage() {
6-
}
7-
8-
public ElfMage(ElfMage mage) {
9-
}
10-
11-
@Override
12-
public Mage clone() throws CloneNotSupportedException {
13-
return new ElfMage(this);
14-
}
15-
16-
@Override
17-
public String toString() {
18-
return "Elven mage";
19-
}
20-
21-
}
1+
package com.iluwatar.prototype;
2+
3+
/**
4+
*
5+
* ElfMage
6+
*
7+
*/
8+
public class ElfMage extends Mage {
9+
10+
public ElfMage() {
11+
}
12+
13+
public ElfMage(ElfMage mage) {
14+
}
15+
16+
@Override
17+
public Mage clone() throws CloneNotSupportedException {
18+
return new ElfMage(this);
19+
}
20+
21+
@Override
22+
public String toString() {
23+
return "Elven mage";
24+
}
25+
26+
}
Lines changed: 26 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,26 @@
1-
package com.iluwatar.prototype;
2-
3-
public class ElfWarlord extends Warlord {
4-
5-
public ElfWarlord() {
6-
}
7-
8-
public ElfWarlord(ElfWarlord warlord) {
9-
}
10-
11-
@Override
12-
public Warlord clone() throws CloneNotSupportedException {
13-
return new ElfWarlord(this);
14-
}
15-
16-
@Override
17-
public String toString() {
18-
return "Elven warlord";
19-
}
20-
21-
}
1+
package com.iluwatar.prototype;
2+
3+
/**
4+
*
5+
* ElfWarlord
6+
*
7+
*/
8+
public class ElfWarlord extends Warlord {
9+
10+
public ElfWarlord() {
11+
}
12+
13+
public ElfWarlord(ElfWarlord warlord) {
14+
}
15+
16+
@Override
17+
public Warlord clone() throws CloneNotSupportedException {
18+
return new ElfWarlord(this);
19+
}
20+
21+
@Override
22+
public String toString() {
23+
return "Elven warlord";
24+
}
25+
26+
}
Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,13 @@
1-
package com.iluwatar.prototype;
2-
3-
public abstract class Mage extends Prototype {
4-
5-
@Override
6-
public abstract Mage clone() throws CloneNotSupportedException;
7-
8-
}
1+
package com.iluwatar.prototype;
2+
3+
/**
4+
*
5+
* Mage
6+
*
7+
*/
8+
public abstract class Mage extends Prototype {
9+
10+
@Override
11+
public abstract Mage clone() throws CloneNotSupportedException;
12+
13+
}
Lines changed: 26 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,26 @@
1-
package com.iluwatar.prototype;
2-
3-
public class OrcBeast extends Beast {
4-
5-
public OrcBeast() {
6-
}
7-
8-
public OrcBeast(OrcBeast beast) {
9-
}
10-
11-
@Override
12-
public Beast clone() throws CloneNotSupportedException {
13-
return new OrcBeast(this);
14-
}
15-
16-
@Override
17-
public String toString() {
18-
return "Orcish wolf";
19-
}
20-
21-
}
1+
package com.iluwatar.prototype;
2+
3+
/**
4+
*
5+
* OrcBeast
6+
*
7+
*/
8+
public class OrcBeast extends Beast {
9+
10+
public OrcBeast() {
11+
}
12+
13+
public OrcBeast(OrcBeast beast) {
14+
}
15+
16+
@Override
17+
public Beast clone() throws CloneNotSupportedException {
18+
return new OrcBeast(this);
19+
}
20+
21+
@Override
22+
public String toString() {
23+
return "Orcish wolf";
24+
}
25+
26+
}
Lines changed: 26 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,26 @@
1-
package com.iluwatar.prototype;
2-
3-
public class OrcMage extends Mage {
4-
5-
public OrcMage() {
6-
}
7-
8-
public OrcMage(OrcMage mage) {
9-
}
10-
11-
@Override
12-
public Mage clone() throws CloneNotSupportedException {
13-
return new OrcMage(this);
14-
}
15-
16-
@Override
17-
public String toString() {
18-
return "Orcish mage";
19-
}
20-
21-
}
1+
package com.iluwatar.prototype;
2+
3+
/**
4+
*
5+
* OrcMage
6+
*
7+
*/
8+
public class OrcMage extends Mage {
9+
10+
public OrcMage() {
11+
}
12+
13+
public OrcMage(OrcMage mage) {
14+
}
15+
16+
@Override
17+
public Mage clone() throws CloneNotSupportedException {
18+
return new OrcMage(this);
19+
}
20+
21+
@Override
22+
public String toString() {
23+
return "Orcish mage";
24+
}
25+
26+
}

0 commit comments

Comments
 (0)
X Tutup