Skip to content

Commit

Permalink
Just formatting App classes to be like the other class files on the p…
Browse files Browse the repository at this point in the history
…roject
  • Loading branch information
lordmat0 committed Oct 7, 2014
1 parent 52f0923 commit bde5b34
Show file tree
Hide file tree
Showing 24 changed files with 465 additions and 507 deletions.
40 changes: 20 additions & 20 deletions abstract-factory/src/main/java/com/iluwatar/App.java
Original file line number Diff line number Diff line change
@@ -1,29 +1,29 @@
package com.iluwatar;

/**
*
* The essence of the Abstract Factory pattern is a factory interface (KingdomFactory)
* and its implementations (ElfKingdomFactory, OrcKingdomFactory).
*
* The example uses both concrete implementations to create a king, a castle and an
* army.
*
* The essence of the Abstract Factory pattern is a factory interface
* (KingdomFactory) and its implementations (ElfKingdomFactory,
* OrcKingdomFactory).
*
* The example uses both concrete implementations to create a king, a castle and
* an army.
*
*/
public class App
{
public static void main( String[] args )
{
createKingdom(new ElfKingdomFactory());
createKingdom(new OrcKingdomFactory());
public class App {

public static void main(String[] args) {
createKingdom(new ElfKingdomFactory());
createKingdom(new OrcKingdomFactory());
}

public static void createKingdom(KingdomFactory factory) {
King king = factory.createKing();
Castle castle = factory.createCastle();
Army army = factory.createArmy();
System.out.println("The kingdom was created.");
System.out.println(king);
System.out.println(castle);
System.out.println(army);
King king = factory.createKing();
Castle castle = factory.createCastle();
Army army = factory.createArmy();
System.out.println("The kingdom was created.");
System.out.println(king);
System.out.println(castle);
System.out.println(army);
}
}
30 changes: 14 additions & 16 deletions adapter/src/main/java/com/iluwatar/App.java
Original file line number Diff line number Diff line change
@@ -1,23 +1,21 @@
package com.iluwatar;

/**
*
* There are two variations of the Adapter pattern: The
* class adapter implements the adaptee's interface whereas
* the object adapter uses composition to contain the adaptee
* in the adapter object. This example uses the object adapter
* approach.
*
* The Adapter (GnomeEngineer) converts the interface of the
* target class (GoblinGlider) into a suitable one expected
* by the client (GnomeEngineeringManager).
*
* There are two variations of the Adapter pattern: The class adapter implements
* the adaptee's interface whereas the object adapter uses composition to
* contain the adaptee in the adapter object. This example uses the object
* adapter approach.
*
* The Adapter (GnomeEngineer) converts the interface of the target class
* (GoblinGlider) into a suitable one expected by the client
* (GnomeEngineeringManager).
*
*/
public class App
{
public static void main( String[] args )
{
GnomeEngineeringManager manager = new GnomeEngineeringManager();
manager.operateDevice();
public class App {

public static void main(String[] args) {
GnomeEngineeringManager manager = new GnomeEngineeringManager();
manager.operateDevice();
}
}
53 changes: 25 additions & 28 deletions bridge/src/main/java/com/iluwatar/App.java
Original file line number Diff line number Diff line change
@@ -1,35 +1,32 @@
package com.iluwatar;

/**
*
* In Bridge pattern both abstraction (MagicWeapon)
* and implementation (MagicWeaponImp) have their
* own class hierarchies. The interface of the
* implementations can be changed without affecting
* the clients.
*
* In Bridge pattern both abstraction (MagicWeapon) and implementation
* (MagicWeaponImp) have their own class hierarchies. The interface of the
* implementations can be changed without affecting the clients.
*
*/
public class App
{
public static void main( String[] args )
{
BlindingMagicWeapon blindingMagicWeapon = new BlindingMagicWeapon(new Excalibur());
blindingMagicWeapon.wield();
blindingMagicWeapon.blind();
blindingMagicWeapon.swing();
blindingMagicWeapon.unwield();

FlyingMagicWeapon flyingMagicWeapon = new FlyingMagicWeapon(new Mjollnir());
flyingMagicWeapon.wield();
flyingMagicWeapon.fly();
flyingMagicWeapon.swing();
flyingMagicWeapon.unwield();

SoulEatingMagicWeapon soulEatingMagicWeapon = new SoulEatingMagicWeapon(new Stormbringer());
soulEatingMagicWeapon.wield();
soulEatingMagicWeapon.swing();
soulEatingMagicWeapon.eatSoul();
soulEatingMagicWeapon.unwield();

public class App {

public static void main(String[] args) {
BlindingMagicWeapon blindingMagicWeapon = new BlindingMagicWeapon(new Excalibur());
blindingMagicWeapon.wield();
blindingMagicWeapon.blind();
blindingMagicWeapon.swing();
blindingMagicWeapon.unwield();

FlyingMagicWeapon flyingMagicWeapon = new FlyingMagicWeapon(new Mjollnir());
flyingMagicWeapon.wield();
flyingMagicWeapon.fly();
flyingMagicWeapon.swing();
flyingMagicWeapon.unwield();

SoulEatingMagicWeapon soulEatingMagicWeapon = new SoulEatingMagicWeapon(new Stormbringer());
soulEatingMagicWeapon.wield();
soulEatingMagicWeapon.swing();
soulEatingMagicWeapon.eatSoul();
soulEatingMagicWeapon.unwield();

}
}
68 changes: 32 additions & 36 deletions builder/src/main/java/com/iluwatar/App.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,45 +3,41 @@
import com.iluwatar.Hero.HeroBuilder;

/**
*
* This is the Builder pattern variation as described by
* Joshua Bloch in Effective Java 2nd Edition.
*
* We want to build Hero objects, but its construction
* is complex because of the many parameters needed. To
* aid the user we introduce HeroBuilder class. HeroBuilder
* takes the minimum parameters to build Hero object in
* its constructor. After that additional configuration
* for the Hero object can be done using the fluent
* HeroBuilder interface. When configuration is ready
* the build method is called to receive the final Hero
* object.
*
* This is the Builder pattern variation as described by Joshua Bloch in
* Effective Java 2nd Edition.
*
* We want to build Hero objects, but its construction is complex because of the
* many parameters needed. To aid the user we introduce HeroBuilder class.
* HeroBuilder takes the minimum parameters to build Hero object in its
* constructor. After that additional configuration for the Hero object can be
* done using the fluent HeroBuilder interface. When configuration is ready the
* build method is called to receive the final Hero object.
*
*/
public class App
{
public static void main( String[] args )
{

Hero mage = new HeroBuilder(Profession.MAGE, "Riobard")
.withHairColor(HairColor.BLACK)
.withWeapon(Weapon.DAGGER)
.build();
System.out.println(mage);
public class App {

public static void main(String[] args) {

Hero mage = new HeroBuilder(Profession.MAGE, "Riobard")
.withHairColor(HairColor.BLACK)
.withWeapon(Weapon.DAGGER)
.build();
System.out.println(mage);

Hero warrior = new HeroBuilder(Profession.WARRIOR, "Amberjill")
.withHairColor(HairColor.BLOND)
.withHairType(HairType.LONG_CURLY)
.withArmor(Armor.CHAIN_MAIL)
.withWeapon(Weapon.SWORD)
.build();
System.out.println(warrior);

Hero warrior = new HeroBuilder(Profession.WARRIOR, "Amberjill")
.withHairColor(HairColor.BLOND)
.withHairType(HairType.LONG_CURLY)
.withArmor(Armor.CHAIN_MAIL)
.withWeapon(Weapon.SWORD)
.build();
System.out.println(warrior);
Hero thief = new HeroBuilder(Profession.THIEF, "Desmond")
.withHairType(HairType.BALD)
.withWeapon(Weapon.BOW)
.build();
System.out.println(thief);

Hero thief = new HeroBuilder(Profession.THIEF, "Desmond")
.withHairType(HairType.BALD)
.withWeapon(Weapon.BOW)
.build();
System.out.println(thief);

}
}
27 changes: 13 additions & 14 deletions chain/src/main/java/com/iluwatar/App.java
Original file line number Diff line number Diff line change
@@ -1,22 +1,21 @@
package com.iluwatar;

/**
*
* Chain of Responsibility organizes request handlers (RequestHandler) into
* a chain where each handler has a chance to act on the request on its
* turn. In this example the king (OrcKing) makes requests and the military
* orcs (OrcCommander, OrcOfficer, OrcSoldier) form the handler chain.
*
* Chain of Responsibility organizes request handlers (RequestHandler) into a
* chain where each handler has a chance to act on the request on its turn. In
* this example the king (OrcKing) makes requests and the military orcs
* (OrcCommander, OrcOfficer, OrcSoldier) form the handler chain.
*
*/
public class App
{
public static void main( String[] args )
{
public class App {

public static void main(String[] args) {

OrcKing king = new OrcKing();
king.makeRequest(new Request(RequestType.DEFEND_CASTLE, "defend castle"));
king.makeRequest(new Request(RequestType.TORTURE_PRISONER, "torture prisoner"));
king.makeRequest(new Request(RequestType.COLLECT_TAX, "collect tax"));

OrcKing king = new OrcKing();
king.makeRequest(new Request(RequestType.DEFEND_CASTLE, "defend castle"));
king.makeRequest(new Request(RequestType.TORTURE_PRISONER, "torture prisoner"));
king.makeRequest(new Request(RequestType.COLLECT_TAX, "collect tax"));

}
}
36 changes: 17 additions & 19 deletions command/src/main/java/com/iluwatar/App.java
Original file line number Diff line number Diff line change
@@ -1,27 +1,25 @@
package com.iluwatar;

/**
*
* In Command pattern actions are objects that can
* be executed and undone. The commands in this example
* are spells cast by the wizard on the goblin.
*
* In Command pattern actions are objects that can be executed and undone. The
* commands in this example are spells cast by the wizard on the goblin.
*
*/
public class App
{
public static void main( String[] args )
{
Wizard wizard = new Wizard();
Goblin goblin = new Goblin();
public class App {

public static void main(String[] args) {
Wizard wizard = new Wizard();
Goblin goblin = new Goblin();

goblin.printStatus();

wizard.castSpell(new ShrinkSpell(), goblin);
goblin.printStatus();

goblin.printStatus();

wizard.castSpell(new ShrinkSpell(), goblin);
goblin.printStatus();

wizard.castSpell(new InvisibilitySpell(), goblin);
goblin.printStatus();
wizard.undoLastSpell();
goblin.printStatus();
wizard.castSpell(new InvisibilitySpell(), goblin);
goblin.printStatus();
wizard.undoLastSpell();
goblin.printStatus();
}
}
35 changes: 17 additions & 18 deletions composite/src/main/java/com/iluwatar/App.java
Original file line number Diff line number Diff line change
@@ -1,26 +1,25 @@
package com.iluwatar;

/**
*
* With Composite we can treat tree hierarchies of objects
* with uniform interface (LetterComposite). In this example
* we have sentences composed of words composed of letters.
*
* With Composite we can treat tree hierarchies of objects with uniform
* interface (LetterComposite). In this example we have sentences composed of
* words composed of letters.
*
*/
public class App
{
public static void main( String[] args )
{
System.out.println("Message from the orcs: ");

LetterComposite orcMessage = new Messenger().messageFromOrcs();
orcMessage.print();
public class App {

public static void main(String[] args) {
System.out.println("Message from the orcs: ");

LetterComposite orcMessage = new Messenger().messageFromOrcs();
orcMessage.print();

System.out.println("\n");

System.out.println("Message from the elves: ");

System.out.println("\n");

System.out.println("Message from the elves: ");

LetterComposite elfMessage = new Messenger().messageFromElves();
elfMessage.print();
LetterComposite elfMessage = new Messenger().messageFromElves();
elfMessage.print();
}
}
34 changes: 16 additions & 18 deletions decorator/src/main/java/com/iluwatar/App.java
Original file line number Diff line number Diff line change
@@ -1,26 +1,24 @@
package com.iluwatar;

/**
*
* Decorator pattern is more flexible alternative to
* subclassing. The decorator class implements the same
* interface as the target and uses composition to
*
* Decorator pattern is more flexible alternative to subclassing. The decorator
* class implements the same interface as the target and uses composition to
* "decorate" calls to the target.
*
*/
public class App
{
public static void main( String[] args )
{

System.out.println("A simple looking troll approaches.");
Hostile troll = new Troll();
troll.attack();
troll.fleeBattle();

System.out.println("\nA smart looking troll surprises you.");
Hostile smart = new SmartTroll(new Troll());
smart.attack();
smart.fleeBattle();
public class App {

public static void main(String[] args) {

System.out.println("A simple looking troll approaches.");
Hostile troll = new Troll();
troll.attack();
troll.fleeBattle();

System.out.println("\nA smart looking troll surprises you.");
Hostile smart = new SmartTroll(new Troll());
smart.attack();
smart.fleeBattle();
}
}
Loading

0 comments on commit bde5b34

Please sign in to comment.