| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
438 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -3,80 +3,78 @@ | |||
| 3 | 3 | ||
| 4 | 4 | /** | |
| 5 | 5 | * | |
| 6 | - * The Abstract Factory pattern provides a way to encapsulate a group of individual | ||
| 7 | - * factories that have a common theme without specifying their concrete classes. In | ||
| 8 | - * normal usage, the client software creates a concrete implementation of the abstract | ||
| 9 | - * factory and then uses the generic interface of the factory to create the concrete | ||
| 10 | - * objects that are part of the theme. The client does not know (or care) which | ||
| 11 | - * concrete objects it gets from each of these internal factories, since it uses only | ||
| 12 | - * the generic interfaces of their products. This pattern separates the details of | ||
| 13 | - * implementation of a set of objects from their general usage and relies on object | ||
| 14 | - * composition, as object creation is implemented in methods exposed in the factory | ||
| 15 | - * interface. | ||
| 6 | + * The Abstract Factory pattern provides a way to encapsulate a group of individual factories that | ||
| 7 | + * have a common theme without specifying their concrete classes. In normal usage, the client | ||
| 8 | + * software creates a concrete implementation of the abstract factory and then uses the generic | ||
| 9 | + * interface of the factory to create the concrete objects that are part of the theme. The client | ||
| 10 | + * does not know (or care) which concrete objects it gets from each of these internal factories, | ||
| 11 | + * since it uses only the generic interfaces of their products. This pattern separates the details | ||
| 12 | + * of implementation of a set of objects from their general usage and relies on object composition, | ||
| 13 | + * as object creation is implemented in methods exposed in the factory interface. | ||
| 16 | 14 | * <p> | |
| 17 | - * The essence of the Abstract Factory pattern is a factory interface | ||
| 18 | - * ({@link KingdomFactory}) and its implementations ({@link ElfKingdomFactory}, | ||
| 19 | - * {@link OrcKingdomFactory}). The example uses both concrete implementations to | ||
| 20 | - * create a king, a castle and an army. | ||
| 15 | + * The essence of the Abstract Factory pattern is a factory interface ({@link KingdomFactory}) and | ||
| 16 | + * its implementations ({@link ElfKingdomFactory}, {@link OrcKingdomFactory}). The example uses both | ||
| 17 | + * concrete implementations to create a king, a castle and an army. | ||
| 21 | 18 | * | |
| 22 | 19 | */ | |
| 23 | 20 | public class App { | |
| 24 | 21 | ||
| 25 | - private King king; | ||
| 26 | - private Castle castle; | ||
| 27 | - private Army army; | ||
| 22 | + private King king; | ||
| 23 | + private Castle castle; | ||
| 24 | + private Army army; | ||
| 28 | 25 | ||
| 29 | - /** | ||
| 30 | - * Creates kingdom | ||
| 31 | - * @param factory | ||
| 32 | - */ | ||
| 33 | - public void createKingdom(final KingdomFactory factory) { | ||
| 34 | - setKing(factory.createKing()); | ||
| 35 | - setCastle(factory.createCastle()); | ||
| 36 | - setArmy(factory.createArmy()); | ||
| 37 | - } | ||
| 38 | - | ||
| 39 | - ElfKingdomFactory getElfKingdomFactory() { | ||
| 40 | - return new ElfKingdomFactory(); | ||
| 41 | - } | ||
| 42 | - | ||
| 43 | - OrcKingdomFactory getOrcKingdomFactory() { | ||
| 44 | - return new OrcKingdomFactory(); | ||
| 45 | - } | ||
| 46 | - | ||
| 47 | - King getKing(final KingdomFactory factory) { | ||
| 48 | - return factory.createKing(); | ||
| 49 | - } | ||
| 50 | - | ||
| 51 | - Castle getCastle(final KingdomFactory factory) { | ||
| 52 | - return factory.createCastle(); | ||
| 53 | - } | ||
| 54 | - | ||
| 55 | - Army getArmy(final KingdomFactory factory) { | ||
| 56 | - return factory.createArmy(); | ||
| 57 | - } | ||
| 58 | - | ||
| 59 | - public King getKing() { | ||
| 60 | - return king; | ||
| 61 | - } | ||
| 62 | - | ||
| 63 | - private void setKing(final King king) { | ||
| 64 | - this.king = king; | ||
| 65 | - } | ||
| 66 | - | ||
| 67 | - public Castle getCastle() { | ||
| 68 | - return castle; | ||
| 69 | - } | ||
| 70 | - | ||
| 71 | - private void setCastle(final Castle castle) { | ||
| 72 | - this.castle = castle; | ||
| 73 | - } | ||
| 74 | - | ||
| 75 | - public Army getArmy() { | ||
| 76 | - return army; | ||
| 77 | - } | ||
| 78 | - | ||
| 79 | - private void setArmy(final Army army) { | ||
| 80 | - this.army = army; | ||
| 81 | - } | ||
| 26 | + /** | ||
| 27 | + * Creates kingdom | ||
| 28 | + * | ||
| 29 | + * @param factory | ||
| 30 | + */ | ||
| 31 | + public void createKingdom(final KingdomFactory factory) { | ||
| 32 | + setKing(factory.createKing()); | ||
| 33 | + setCastle(factory.createCastle()); | ||
| 34 | + setArmy(factory.createArmy()); | ||
| 35 | + } | ||
| 36 | + | ||
| 37 | + ElfKingdomFactory getElfKingdomFactory() { | ||
| 38 | + return new ElfKingdomFactory(); | ||
| 39 | + } | ||
| 40 | + | ||
| 41 | + OrcKingdomFactory getOrcKingdomFactory() { | ||
| 42 | + return new OrcKingdomFactory(); | ||
| 43 | + } | ||
| 44 | + | ||
| 45 | + King getKing(final KingdomFactory factory) { | ||
| 46 | + return factory.createKing(); | ||
| 47 | + } | ||
| 48 | + | ||
| 49 | + Castle getCastle(final KingdomFactory factory) { | ||
| 50 | + return factory.createCastle(); | ||
| 51 | + } | ||
| 52 | + | ||
| 53 | + Army getArmy(final KingdomFactory factory) { | ||
| 54 | + return factory.createArmy(); | ||
| 55 | + } | ||
| 56 | + | ||
| 57 | + public King getKing() { | ||
| 58 | + return king; | ||
| 59 | + } | ||
| 60 | + | ||
| 61 | + private void setKing(final King king) { | ||
| 62 | + this.king = king; | ||
| 63 | + } | ||
| 64 | + | ||
| 65 | + public Castle getCastle() { | ||
| 66 | + return castle; | ||
| 67 | + } | ||
| 68 | + | ||
| 69 | + private void setCastle(final Castle castle) { | ||
| 70 | + this.castle = castle; | ||
| 71 | + } | ||
| 72 | + | ||
| 73 | + public Army getArmy() { | ||
| 74 | + return army; | ||
| 75 | + } | ||
| 76 | + | ||
| 77 | + private void setArmy(final Army army) { | ||
| 78 | + this.army = army; | ||
| 79 | + } | ||
| 82 | 80 | } | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -7,5 +7,5 @@ | |||
| 7 | 7 | */ | |
| 8 | 8 | public interface Army { | |
| 9 | 9 | ||
| 10 | - String getDescription(); | ||
| 10 | + String getDescription(); | ||
| 11 | 11 | } | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -7,5 +7,5 @@ | |||
| 7 | 7 | */ | |
| 8 | 8 | public interface Castle { | |
| 9 | 9 | ||
| 10 | - String getDescription(); | ||
| 10 | + String getDescription(); | ||
| 11 | 11 | } | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -7,10 +7,10 @@ | |||
| 7 | 7 | */ | |
| 8 | 8 | public class ElfArmy implements Army { | |
| 9 | 9 | ||
| 10 | - static final String DESCRIPTION = "This is the Elven Army!"; | ||
| 10 | + static final String DESCRIPTION = "This is the Elven Army!"; | ||
| 11 | 11 | ||
| 12 | - @Override | ||
| 13 | - public String getDescription() { | ||
| 14 | - return DESCRIPTION; | ||
| 15 | - } | ||
| 12 | + @Override | ||
| 13 | + public String getDescription() { | ||
| 14 | + return DESCRIPTION; | ||
| 15 | + } | ||
| 16 | 16 | } | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -7,10 +7,10 @@ | |||
| 7 | 7 | */ | |
| 8 | 8 | public class ElfCastle implements Castle { | |
| 9 | 9 | ||
| 10 | - static final String DESCRIPTION = "This is the Elven castle!"; | ||
| 10 | + static final String DESCRIPTION = "This is the Elven castle!"; | ||
| 11 | 11 | ||
| 12 | - @Override | ||
| 13 | - public String getDescription() { | ||
| 14 | - return DESCRIPTION; | ||
| 15 | - } | ||
| 12 | + @Override | ||
| 13 | + public String getDescription() { | ||
| 14 | + return DESCRIPTION; | ||
| 15 | + } | ||
| 16 | 16 | } | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -7,10 +7,10 @@ | |||
| 7 | 7 | */ | |
| 8 | 8 | public class ElfKing implements King { | |
| 9 | 9 | ||
| 10 | - static final String DESCRIPTION = "This is the Elven king!"; | ||
| 11 | - | ||
| 12 | - @Override | ||
| 13 | - public String getDescription() { | ||
| 14 | - return DESCRIPTION; | ||
| 15 | - } | ||
| 10 | + static final String DESCRIPTION = "This is the Elven king!"; | ||
| 11 | + | ||
| 12 | + @Override | ||
| 13 | + public String getDescription() { | ||
| 14 | + return DESCRIPTION; | ||
| 15 | + } | ||
| 16 | 16 | } | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -7,16 +7,16 @@ | |||
| 7 | 7 | */ | |
| 8 | 8 | public class ElfKingdomFactory implements KingdomFactory { | |
| 9 | 9 | ||
| 10 | - public Castle createCastle() { | ||
| 11 | - return new ElfCastle(); | ||
| 12 | - } | ||
| 10 | + public Castle createCastle() { | ||
| 11 | + return new ElfCastle(); | ||
| 12 | + } | ||
| 13 | 13 | ||
| 14 | - public King createKing() { | ||
| 15 | - return new ElfKing(); | ||
| 16 | - } | ||
| 14 | + public King createKing() { | ||
| 15 | + return new ElfKing(); | ||
| 16 | + } | ||
| 17 | 17 | ||
| 18 | - public Army createArmy() { | ||
| 19 | - return new ElfArmy(); | ||
| 20 | - } | ||
| 18 | + public Army createArmy() { | ||
| 19 | + return new ElfArmy(); | ||
| 20 | + } | ||
| 21 | 21 | ||
| 22 | 22 | } | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -7,5 +7,5 @@ | |||
| 7 | 7 | */ | |
| 8 | 8 | public interface King { | |
| 9 | 9 | ||
| 10 | - String getDescription(); | ||
| 10 | + String getDescription(); | ||
| 11 | 11 | } | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -7,10 +7,10 @@ | |||
| 7 | 7 | */ | |
| 8 | 8 | public interface KingdomFactory { | |
| 9 | 9 | ||
| 10 | - Castle createCastle(); | ||
| 10 | + Castle createCastle(); | ||
| 11 | 11 | ||
| 12 | - King createKing(); | ||
| 12 | + King createKing(); | ||
| 13 | 13 | ||
| 14 | - Army createArmy(); | ||
| 14 | + Army createArmy(); | ||
| 15 | 15 | ||
| 16 | 16 | } | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -7,10 +7,10 @@ | |||
| 7 | 7 | */ | |
| 8 | 8 | public class OrcArmy implements Army { | |
| 9 | 9 | ||
| 10 | - static final String DESCRIPTION = "This is the Orc Army!"; | ||
| 10 | + static final String DESCRIPTION = "This is the Orc Army!"; | ||
| 11 | 11 | ||
| 12 | - @Override | ||
| 13 | - public String getDescription() { | ||
| 14 | - return DESCRIPTION; | ||
| 15 | - } | ||
| 12 | + @Override | ||
| 13 | + public String getDescription() { | ||
| 14 | + return DESCRIPTION; | ||
| 15 | + } | ||
| 16 | 16 | } | |
| Back | FazBrowse Home | New Git URL |
0 commit comments