Formatted all files to the same standard
This commit is contained in:
@ -1,34 +1,36 @@
|
||||
package com.iluwatar;
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
* 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;
|
||||
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 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);
|
||||
}
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
@ -4,5 +4,5 @@ public abstract class Beast extends Prototype {
|
||||
|
||||
@Override
|
||||
public abstract Beast clone() throws CloneNotSupportedException;
|
||||
|
||||
|
||||
}
|
||||
|
@ -4,10 +4,10 @@ public class ElfBeast extends Beast {
|
||||
|
||||
public ElfBeast() {
|
||||
}
|
||||
|
||||
|
||||
public ElfBeast(ElfBeast beast) {
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public Beast clone() throws CloneNotSupportedException {
|
||||
return new ElfBeast(this);
|
||||
|
@ -4,10 +4,10 @@ public class ElfMage extends Mage {
|
||||
|
||||
public ElfMage() {
|
||||
}
|
||||
|
||||
|
||||
public ElfMage(ElfMage mage) {
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public Mage clone() throws CloneNotSupportedException {
|
||||
return new ElfMage(this);
|
||||
|
@ -4,10 +4,10 @@ public class ElfWarlord extends Warlord {
|
||||
|
||||
public ElfWarlord() {
|
||||
}
|
||||
|
||||
|
||||
public ElfWarlord(ElfWarlord warlord) {
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public Warlord clone() throws CloneNotSupportedException {
|
||||
return new ElfWarlord(this);
|
||||
|
@ -3,14 +3,14 @@ package com.iluwatar;
|
||||
/**
|
||||
*
|
||||
* Interface for the factory class.
|
||||
*
|
||||
*
|
||||
*/
|
||||
public interface HeroFactory {
|
||||
|
||||
Mage createMage();
|
||||
|
||||
|
||||
Warlord createWarlord();
|
||||
|
||||
|
||||
Beast createBeast();
|
||||
|
||||
|
||||
}
|
||||
|
@ -3,7 +3,7 @@ package com.iluwatar;
|
||||
/**
|
||||
*
|
||||
* Concrete factory class.
|
||||
*
|
||||
*
|
||||
*/
|
||||
public class HeroFactoryImpl implements HeroFactory {
|
||||
|
||||
@ -16,7 +16,7 @@ public class HeroFactoryImpl implements HeroFactory {
|
||||
this.warlord = warlord;
|
||||
this.beast = beast;
|
||||
}
|
||||
|
||||
|
||||
public Mage createMage() {
|
||||
try {
|
||||
return mage.clone();
|
||||
@ -24,7 +24,7 @@ public class HeroFactoryImpl implements HeroFactory {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public Warlord createWarlord() {
|
||||
try {
|
||||
return warlord.clone();
|
||||
@ -32,7 +32,7 @@ public class HeroFactoryImpl implements HeroFactory {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public Beast createBeast() {
|
||||
try {
|
||||
return beast.clone();
|
||||
@ -40,5 +40,5 @@ public class HeroFactoryImpl implements HeroFactory {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
@ -4,5 +4,5 @@ public abstract class Mage extends Prototype {
|
||||
|
||||
@Override
|
||||
public abstract Mage clone() throws CloneNotSupportedException;
|
||||
|
||||
|
||||
}
|
||||
|
@ -4,10 +4,10 @@ public class OrcBeast extends Beast {
|
||||
|
||||
public OrcBeast() {
|
||||
}
|
||||
|
||||
|
||||
public OrcBeast(OrcBeast beast) {
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public Beast clone() throws CloneNotSupportedException {
|
||||
return new OrcBeast(this);
|
||||
@ -17,5 +17,5 @@ public class OrcBeast extends Beast {
|
||||
public String toString() {
|
||||
return "Orcish wolf";
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
@ -4,10 +4,10 @@ public class OrcMage extends Mage {
|
||||
|
||||
public OrcMage() {
|
||||
}
|
||||
|
||||
|
||||
public OrcMage(OrcMage mage) {
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public Mage clone() throws CloneNotSupportedException {
|
||||
return new OrcMage(this);
|
||||
@ -17,5 +17,5 @@ public class OrcMage extends Mage {
|
||||
public String toString() {
|
||||
return "Orcish mage";
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
@ -4,10 +4,10 @@ public class OrcWarlord extends Warlord {
|
||||
|
||||
public OrcWarlord() {
|
||||
}
|
||||
|
||||
|
||||
public OrcWarlord(OrcWarlord warlord) {
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public Warlord clone() throws CloneNotSupportedException {
|
||||
return new OrcWarlord(this);
|
||||
@ -17,5 +17,5 @@ public class OrcWarlord extends Warlord {
|
||||
public String toString() {
|
||||
return "Orcish warlord";
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
@ -4,5 +4,5 @@ public abstract class Prototype implements Cloneable {
|
||||
|
||||
@Override
|
||||
public abstract Object clone() throws CloneNotSupportedException;
|
||||
|
||||
|
||||
}
|
||||
|
@ -4,5 +4,5 @@ public abstract class Warlord extends Prototype {
|
||||
|
||||
@Override
|
||||
public abstract Warlord clone() throws CloneNotSupportedException;
|
||||
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user