#107 Improve JavaDoc for Prototype
This commit is contained in:
parent
8fb0ec1bf9
commit
0db6581cfd
@ -1,36 +1,40 @@
|
||||
package com.iluwatar.prototype;
|
||||
|
||||
/**
|
||||
*
|
||||
* In Prototype we have a factory class (HeroFactoryImpl) producing objects by
|
||||
* cloning existing ones. In this example the factory's prototype objects are
|
||||
* given as constructor parameters.
|
||||
*
|
||||
*/
|
||||
public class App {
|
||||
|
||||
public static void main(String[] args) {
|
||||
HeroFactory factory;
|
||||
Mage mage;
|
||||
Warlord warlord;
|
||||
Beast beast;
|
||||
|
||||
factory = new HeroFactoryImpl(new ElfMage(), new ElfWarlord(),
|
||||
new ElfBeast());
|
||||
mage = factory.createMage();
|
||||
warlord = factory.createWarlord();
|
||||
beast = factory.createBeast();
|
||||
System.out.println(mage);
|
||||
System.out.println(warlord);
|
||||
System.out.println(beast);
|
||||
|
||||
factory = new HeroFactoryImpl(new OrcMage(), new OrcWarlord(),
|
||||
new OrcBeast());
|
||||
mage = factory.createMage();
|
||||
warlord = factory.createWarlord();
|
||||
beast = factory.createBeast();
|
||||
System.out.println(mage);
|
||||
System.out.println(warlord);
|
||||
System.out.println(beast);
|
||||
}
|
||||
}
|
||||
package com.iluwatar.prototype;
|
||||
|
||||
/**
|
||||
*
|
||||
* In Prototype we have a factory class ({@link HeroFactoryImpl}) producing objects by
|
||||
* cloning the existing ones. In this example the factory's prototype objects are
|
||||
* given as constructor parameters.
|
||||
*
|
||||
*/
|
||||
public class App {
|
||||
|
||||
/**
|
||||
* Program entry point
|
||||
* @param args command line args
|
||||
*/
|
||||
public static void main(String[] args) {
|
||||
HeroFactory factory;
|
||||
Mage mage;
|
||||
Warlord warlord;
|
||||
Beast beast;
|
||||
|
||||
factory = new HeroFactoryImpl(new ElfMage(), new ElfWarlord(),
|
||||
new ElfBeast());
|
||||
mage = factory.createMage();
|
||||
warlord = factory.createWarlord();
|
||||
beast = factory.createBeast();
|
||||
System.out.println(mage);
|
||||
System.out.println(warlord);
|
||||
System.out.println(beast);
|
||||
|
||||
factory = new HeroFactoryImpl(new OrcMage(), new OrcWarlord(),
|
||||
new OrcBeast());
|
||||
mage = factory.createMage();
|
||||
warlord = factory.createWarlord();
|
||||
beast = factory.createBeast();
|
||||
System.out.println(mage);
|
||||
System.out.println(warlord);
|
||||
System.out.println(beast);
|
||||
}
|
||||
}
|
||||
|
@ -1,8 +1,13 @@
|
||||
package com.iluwatar.prototype;
|
||||
|
||||
public abstract class Beast extends Prototype {
|
||||
|
||||
@Override
|
||||
public abstract Beast clone() throws CloneNotSupportedException;
|
||||
|
||||
}
|
||||
package com.iluwatar.prototype;
|
||||
|
||||
/**
|
||||
*
|
||||
* Beast
|
||||
*
|
||||
*/
|
||||
public abstract class Beast extends Prototype {
|
||||
|
||||
@Override
|
||||
public abstract Beast clone() throws CloneNotSupportedException;
|
||||
|
||||
}
|
||||
|
@ -1,21 +1,26 @@
|
||||
package com.iluwatar.prototype;
|
||||
|
||||
public class ElfBeast extends Beast {
|
||||
|
||||
public ElfBeast() {
|
||||
}
|
||||
|
||||
public ElfBeast(ElfBeast beast) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Beast clone() throws CloneNotSupportedException {
|
||||
return new ElfBeast(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "Elven eagle";
|
||||
}
|
||||
|
||||
}
|
||||
package com.iluwatar.prototype;
|
||||
|
||||
/**
|
||||
*
|
||||
* ElfBeast
|
||||
*
|
||||
*/
|
||||
public class ElfBeast extends Beast {
|
||||
|
||||
public ElfBeast() {
|
||||
}
|
||||
|
||||
public ElfBeast(ElfBeast beast) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Beast clone() throws CloneNotSupportedException {
|
||||
return new ElfBeast(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "Elven eagle";
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,21 +1,26 @@
|
||||
package com.iluwatar.prototype;
|
||||
|
||||
public class ElfMage extends Mage {
|
||||
|
||||
public ElfMage() {
|
||||
}
|
||||
|
||||
public ElfMage(ElfMage mage) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Mage clone() throws CloneNotSupportedException {
|
||||
return new ElfMage(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "Elven mage";
|
||||
}
|
||||
|
||||
}
|
||||
package com.iluwatar.prototype;
|
||||
|
||||
/**
|
||||
*
|
||||
* ElfMage
|
||||
*
|
||||
*/
|
||||
public class ElfMage extends Mage {
|
||||
|
||||
public ElfMage() {
|
||||
}
|
||||
|
||||
public ElfMage(ElfMage mage) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Mage clone() throws CloneNotSupportedException {
|
||||
return new ElfMage(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "Elven mage";
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,21 +1,26 @@
|
||||
package com.iluwatar.prototype;
|
||||
|
||||
public class ElfWarlord extends Warlord {
|
||||
|
||||
public ElfWarlord() {
|
||||
}
|
||||
|
||||
public ElfWarlord(ElfWarlord warlord) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Warlord clone() throws CloneNotSupportedException {
|
||||
return new ElfWarlord(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "Elven warlord";
|
||||
}
|
||||
|
||||
}
|
||||
package com.iluwatar.prototype;
|
||||
|
||||
/**
|
||||
*
|
||||
* ElfWarlord
|
||||
*
|
||||
*/
|
||||
public class ElfWarlord extends Warlord {
|
||||
|
||||
public ElfWarlord() {
|
||||
}
|
||||
|
||||
public ElfWarlord(ElfWarlord warlord) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Warlord clone() throws CloneNotSupportedException {
|
||||
return new ElfWarlord(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "Elven warlord";
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,8 +1,13 @@
|
||||
package com.iluwatar.prototype;
|
||||
|
||||
public abstract class Mage extends Prototype {
|
||||
|
||||
@Override
|
||||
public abstract Mage clone() throws CloneNotSupportedException;
|
||||
|
||||
}
|
||||
package com.iluwatar.prototype;
|
||||
|
||||
/**
|
||||
*
|
||||
* Mage
|
||||
*
|
||||
*/
|
||||
public abstract class Mage extends Prototype {
|
||||
|
||||
@Override
|
||||
public abstract Mage clone() throws CloneNotSupportedException;
|
||||
|
||||
}
|
||||
|
@ -1,21 +1,26 @@
|
||||
package com.iluwatar.prototype;
|
||||
|
||||
public class OrcBeast extends Beast {
|
||||
|
||||
public OrcBeast() {
|
||||
}
|
||||
|
||||
public OrcBeast(OrcBeast beast) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Beast clone() throws CloneNotSupportedException {
|
||||
return new OrcBeast(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "Orcish wolf";
|
||||
}
|
||||
|
||||
}
|
||||
package com.iluwatar.prototype;
|
||||
|
||||
/**
|
||||
*
|
||||
* OrcBeast
|
||||
*
|
||||
*/
|
||||
public class OrcBeast extends Beast {
|
||||
|
||||
public OrcBeast() {
|
||||
}
|
||||
|
||||
public OrcBeast(OrcBeast beast) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Beast clone() throws CloneNotSupportedException {
|
||||
return new OrcBeast(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "Orcish wolf";
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,21 +1,26 @@
|
||||
package com.iluwatar.prototype;
|
||||
|
||||
public class OrcMage extends Mage {
|
||||
|
||||
public OrcMage() {
|
||||
}
|
||||
|
||||
public OrcMage(OrcMage mage) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Mage clone() throws CloneNotSupportedException {
|
||||
return new OrcMage(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "Orcish mage";
|
||||
}
|
||||
|
||||
}
|
||||
package com.iluwatar.prototype;
|
||||
|
||||
/**
|
||||
*
|
||||
* OrcMage
|
||||
*
|
||||
*/
|
||||
public class OrcMage extends Mage {
|
||||
|
||||
public OrcMage() {
|
||||
}
|
||||
|
||||
public OrcMage(OrcMage mage) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Mage clone() throws CloneNotSupportedException {
|
||||
return new OrcMage(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "Orcish mage";
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,21 +1,26 @@
|
||||
package com.iluwatar.prototype;
|
||||
|
||||
public class OrcWarlord extends Warlord {
|
||||
|
||||
public OrcWarlord() {
|
||||
}
|
||||
|
||||
public OrcWarlord(OrcWarlord warlord) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Warlord clone() throws CloneNotSupportedException {
|
||||
return new OrcWarlord(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "Orcish warlord";
|
||||
}
|
||||
|
||||
}
|
||||
package com.iluwatar.prototype;
|
||||
|
||||
/**
|
||||
*
|
||||
* OrcWarlord
|
||||
*
|
||||
*/
|
||||
public class OrcWarlord extends Warlord {
|
||||
|
||||
public OrcWarlord() {
|
||||
}
|
||||
|
||||
public OrcWarlord(OrcWarlord warlord) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Warlord clone() throws CloneNotSupportedException {
|
||||
return new OrcWarlord(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "Orcish warlord";
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,8 +1,13 @@
|
||||
package com.iluwatar.prototype;
|
||||
|
||||
public abstract class Prototype implements Cloneable {
|
||||
|
||||
@Override
|
||||
public abstract Object clone() throws CloneNotSupportedException;
|
||||
|
||||
}
|
||||
package com.iluwatar.prototype;
|
||||
|
||||
/**
|
||||
*
|
||||
* Prototype
|
||||
*
|
||||
*/
|
||||
public abstract class Prototype implements Cloneable {
|
||||
|
||||
@Override
|
||||
public abstract Object clone() throws CloneNotSupportedException;
|
||||
|
||||
}
|
||||
|
@ -1,8 +1,13 @@
|
||||
package com.iluwatar.prototype;
|
||||
|
||||
public abstract class Warlord extends Prototype {
|
||||
|
||||
@Override
|
||||
public abstract Warlord clone() throws CloneNotSupportedException;
|
||||
|
||||
}
|
||||
package com.iluwatar.prototype;
|
||||
|
||||
/**
|
||||
*
|
||||
* Warlord
|
||||
*
|
||||
*/
|
||||
public abstract class Warlord extends Prototype {
|
||||
|
||||
@Override
|
||||
public abstract Warlord clone() throws CloneNotSupportedException;
|
||||
|
||||
}
|
||||
|
@ -1,14 +1,19 @@
|
||||
package com.iluwatar.prototype;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import com.iluwatar.prototype.App;
|
||||
|
||||
public class AppTest {
|
||||
|
||||
@Test
|
||||
public void test() {
|
||||
String[] args = {};
|
||||
App.main(args);
|
||||
}
|
||||
}
|
||||
package com.iluwatar.prototype;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import com.iluwatar.prototype.App;
|
||||
|
||||
/**
|
||||
*
|
||||
* Application test
|
||||
*
|
||||
*/
|
||||
public class AppTest {
|
||||
|
||||
@Test
|
||||
public void test() {
|
||||
String[] args = {};
|
||||
App.main(args);
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user