Skip to content

Commit bde5b34

Browse files
committed
Just formatting App classes to be like the other class files on the project
1 parent 52f0923 commit bde5b34

File tree

24 files changed

+465
-507
lines changed
  • abstract-factory/src/main/java/com/iluwatar
  • adapter/src/main/java/com/iluwatar
  • bridge/src/main/java/com/iluwatar
  • builder/src/main/java/com/iluwatar
  • chain/src/main/java/com/iluwatar
  • command/src/main/java/com/iluwatar
  • composite/src/main/java/com/iluwatar
  • decorator/src/main/java/com/iluwatar
  • double-checked-locking/src/main/java/com/iluwatar
  • facade/src/main/java/com/iluwatar
  • factory-method/src/main/java/com/iluwatar
  • flyweight/src/main/java/com/iluwatar
  • interpreter/src/main/java/com/iluwatar
  • iterator/src/main/java/com/iluwatar
  • mediator/src/main/java/com/iluwatar
  • memento/src/main/java/com/iluwatar
  • observer/src/main/java/com/iluwatar
  • prototype/src/main/java/com/iluwatar
  • proxy/src/main/java/com/iluwatar
  • singleton/src/main/java/com/iluwatar
  • state/src/main/java/com/iluwatar
  • strategy/src/main/java/com/iluwatar
  • template-method/src/main/java/com/iluwatar
  • visitor/src/main/java/com/iluwatar

24 files changed

+465
-507
lines changed
Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,29 @@
11
package com.iluwatar;
22

33
/**
4-
*
5-
* The essence of the Abstract Factory pattern is a factory interface (KingdomFactory)
6-
* and its implementations (ElfKingdomFactory, OrcKingdomFactory).
7-
*
8-
* The example uses both concrete implementations to create a king, a castle and an
9-
* army.
4+
*
5+
* The essence of the Abstract Factory pattern is a factory interface
6+
* (KingdomFactory) and its implementations (ElfKingdomFactory,
7+
* OrcKingdomFactory).
8+
*
9+
* The example uses both concrete implementations to create a king, a castle and
10+
* an army.
1011
*
1112
*/
12-
public class App
13-
{
14-
public static void main( String[] args )
15-
{
16-
createKingdom(new ElfKingdomFactory());
17-
createKingdom(new OrcKingdomFactory());
13+
public class App {
14+
15+
public static void main(String[] args) {
16+
createKingdom(new ElfKingdomFactory());
17+
createKingdom(new OrcKingdomFactory());
1818
}
19-
19+
2020
public static void createKingdom(KingdomFactory factory) {
21-
King king = factory.createKing();
22-
Castle castle = factory.createCastle();
23-
Army army = factory.createArmy();
24-
System.out.println("The kingdom was created.");
25-
System.out.println(king);
26-
System.out.println(castle);
27-
System.out.println(army);
21+
King king = factory.createKing();
22+
Castle castle = factory.createCastle();
23+
Army army = factory.createArmy();
24+
System.out.println("The kingdom was created.");
25+
System.out.println(king);
26+
System.out.println(castle);
27+
System.out.println(army);
2828
}
2929
}
Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,21 @@
11
package com.iluwatar;
22

33
/**
4-
*
5-
* There are two variations of the Adapter pattern: The
6-
* class adapter implements the adaptee's interface whereas
7-
* the object adapter uses composition to contain the adaptee
8-
* in the adapter object. This example uses the object adapter
9-
* approach.
10-
*
11-
* The Adapter (GnomeEngineer) converts the interface of the
12-
* target class (GoblinGlider) into a suitable one expected
13-
* by the client (GnomeEngineeringManager).
4+
*
5+
* There are two variations of the Adapter pattern: The class adapter implements
6+
* the adaptee's interface whereas the object adapter uses composition to
7+
* contain the adaptee in the adapter object. This example uses the object
8+
* adapter approach.
9+
*
10+
* The Adapter (GnomeEngineer) converts the interface of the target class
11+
* (GoblinGlider) into a suitable one expected by the client
12+
* (GnomeEngineeringManager).
1413
*
1514
*/
16-
public class App
17-
{
18-
public static void main( String[] args )
19-
{
20-
GnomeEngineeringManager manager = new GnomeEngineeringManager();
21-
manager.operateDevice();
15+
public class App {
16+
17+
public static void main(String[] args) {
18+
GnomeEngineeringManager manager = new GnomeEngineeringManager();
19+
manager.operateDevice();
2220
}
2321
}
Lines changed: 25 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,32 @@
11
package com.iluwatar;
22

33
/**
4-
*
5-
* In Bridge pattern both abstraction (MagicWeapon)
6-
* and implementation (MagicWeaponImp) have their
7-
* own class hierarchies. The interface of the
8-
* implementations can be changed without affecting
9-
* the clients.
4+
*
5+
* In Bridge pattern both abstraction (MagicWeapon) and implementation
6+
* (MagicWeaponImp) have their own class hierarchies. The interface of the
7+
* implementations can be changed without affecting the clients.
108
*
119
*/
12-
public class App
13-
{
14-
public static void main( String[] args )
15-
{
16-
BlindingMagicWeapon blindingMagicWeapon = new BlindingMagicWeapon(new Excalibur());
17-
blindingMagicWeapon.wield();
18-
blindingMagicWeapon.blind();
19-
blindingMagicWeapon.swing();
20-
blindingMagicWeapon.unwield();
21-
22-
FlyingMagicWeapon flyingMagicWeapon = new FlyingMagicWeapon(new Mjollnir());
23-
flyingMagicWeapon.wield();
24-
flyingMagicWeapon.fly();
25-
flyingMagicWeapon.swing();
26-
flyingMagicWeapon.unwield();
27-
28-
SoulEatingMagicWeapon soulEatingMagicWeapon = new SoulEatingMagicWeapon(new Stormbringer());
29-
soulEatingMagicWeapon.wield();
30-
soulEatingMagicWeapon.swing();
31-
soulEatingMagicWeapon.eatSoul();
32-
soulEatingMagicWeapon.unwield();
33-
10+
public class App {
11+
12+
public static void main(String[] args) {
13+
BlindingMagicWeapon blindingMagicWeapon = new BlindingMagicWeapon(new Excalibur());
14+
blindingMagicWeapon.wield();
15+
blindingMagicWeapon.blind();
16+
blindingMagicWeapon.swing();
17+
blindingMagicWeapon.unwield();
18+
19+
FlyingMagicWeapon flyingMagicWeapon = new FlyingMagicWeapon(new Mjollnir());
20+
flyingMagicWeapon.wield();
21+
flyingMagicWeapon.fly();
22+
flyingMagicWeapon.swing();
23+
flyingMagicWeapon.unwield();
24+
25+
SoulEatingMagicWeapon soulEatingMagicWeapon = new SoulEatingMagicWeapon(new Stormbringer());
26+
soulEatingMagicWeapon.wield();
27+
soulEatingMagicWeapon.swing();
28+
soulEatingMagicWeapon.eatSoul();
29+
soulEatingMagicWeapon.unwield();
30+
3431
}
3532
}

builder/src/main/java/com/iluwatar/App.java

Lines changed: 32 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -3,45 +3,41 @@
33
import com.iluwatar.Hero.HeroBuilder;
44

55
/**
6-
*
7-
* This is the Builder pattern variation as described by
8-
* Joshua Bloch in Effective Java 2nd Edition.
9-
*
10-
* We want to build Hero objects, but its construction
11-
* is complex because of the many parameters needed. To
12-
* aid the user we introduce HeroBuilder class. HeroBuilder
13-
* takes the minimum parameters to build Hero object in
14-
* its constructor. After that additional configuration
15-
* for the Hero object can be done using the fluent
16-
* HeroBuilder interface. When configuration is ready
17-
* the build method is called to receive the final Hero
18-
* object.
6+
*
7+
* This is the Builder pattern variation as described by Joshua Bloch in
8+
* Effective Java 2nd Edition.
9+
*
10+
* We want to build Hero objects, but its construction is complex because of the
11+
* many parameters needed. To aid the user we introduce HeroBuilder class.
12+
* HeroBuilder takes the minimum parameters to build Hero object in its
13+
* constructor. After that additional configuration for the Hero object can be
14+
* done using the fluent HeroBuilder interface. When configuration is ready the
15+
* build method is called to receive the final Hero object.
1916
*
2017
*/
21-
public class App
22-
{
23-
public static void main( String[] args )
24-
{
25-
26-
Hero mage = new HeroBuilder(Profession.MAGE, "Riobard")
27-
.withHairColor(HairColor.BLACK)
28-
.withWeapon(Weapon.DAGGER)
29-
.build();
30-
System.out.println(mage);
18+
public class App {
19+
20+
public static void main(String[] args) {
21+
22+
Hero mage = new HeroBuilder(Profession.MAGE, "Riobard")
23+
.withHairColor(HairColor.BLACK)
24+
.withWeapon(Weapon.DAGGER)
25+
.build();
26+
System.out.println(mage);
27+
28+
Hero warrior = new HeroBuilder(Profession.WARRIOR, "Amberjill")
29+
.withHairColor(HairColor.BLOND)
30+
.withHairType(HairType.LONG_CURLY)
31+
.withArmor(Armor.CHAIN_MAIL)
32+
.withWeapon(Weapon.SWORD)
33+
.build();
34+
System.out.println(warrior);
3135

32-
Hero warrior = new HeroBuilder(Profession.WARRIOR, "Amberjill")
33-
.withHairColor(HairColor.BLOND)
34-
.withHairType(HairType.LONG_CURLY)
35-
.withArmor(Armor.CHAIN_MAIL)
36-
.withWeapon(Weapon.SWORD)
37-
.build();
38-
System.out.println(warrior);
36+
Hero thief = new HeroBuilder(Profession.THIEF, "Desmond")
37+
.withHairType(HairType.BALD)
38+
.withWeapon(Weapon.BOW)
39+
.build();
40+
System.out.println(thief);
3941

40-
Hero thief = new HeroBuilder(Profession.THIEF, "Desmond")
41-
.withHairType(HairType.BALD)
42-
.withWeapon(Weapon.BOW)
43-
.build();
44-
System.out.println(thief);
45-
4642
}
4743
}
Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,21 @@
11
package com.iluwatar;
22

33
/**
4-
*
5-
* Chain of Responsibility organizes request handlers (RequestHandler) into
6-
* a chain where each handler has a chance to act on the request on its
7-
* turn. In this example the king (OrcKing) makes requests and the military
8-
* orcs (OrcCommander, OrcOfficer, OrcSoldier) form the handler chain.
4+
*
5+
* Chain of Responsibility organizes request handlers (RequestHandler) into a
6+
* chain where each handler has a chance to act on the request on its turn. In
7+
* this example the king (OrcKing) makes requests and the military orcs
8+
* (OrcCommander, OrcOfficer, OrcSoldier) form the handler chain.
99
*
1010
*/
11-
public class App
12-
{
13-
public static void main( String[] args )
14-
{
11+
public class App {
12+
13+
public static void main(String[] args) {
14+
15+
OrcKing king = new OrcKing();
16+
king.makeRequest(new Request(RequestType.DEFEND_CASTLE, "defend castle"));
17+
king.makeRequest(new Request(RequestType.TORTURE_PRISONER, "torture prisoner"));
18+
king.makeRequest(new Request(RequestType.COLLECT_TAX, "collect tax"));
1519

16-
OrcKing king = new OrcKing();
17-
king.makeRequest(new Request(RequestType.DEFEND_CASTLE, "defend castle"));
18-
king.makeRequest(new Request(RequestType.TORTURE_PRISONER, "torture prisoner"));
19-
king.makeRequest(new Request(RequestType.COLLECT_TAX, "collect tax"));
20-
2120
}
2221
}
Lines changed: 17 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,25 @@
11
package com.iluwatar;
22

33
/**
4-
*
5-
* In Command pattern actions are objects that can
6-
* be executed and undone. The commands in this example
7-
* are spells cast by the wizard on the goblin.
4+
*
5+
* In Command pattern actions are objects that can be executed and undone. The
6+
* commands in this example are spells cast by the wizard on the goblin.
87
*
98
*/
10-
public class App
11-
{
12-
public static void main( String[] args )
13-
{
14-
Wizard wizard = new Wizard();
15-
Goblin goblin = new Goblin();
9+
public class App {
10+
11+
public static void main(String[] args) {
12+
Wizard wizard = new Wizard();
13+
Goblin goblin = new Goblin();
14+
15+
goblin.printStatus();
16+
17+
wizard.castSpell(new ShrinkSpell(), goblin);
18+
goblin.printStatus();
1619

17-
goblin.printStatus();
18-
19-
wizard.castSpell(new ShrinkSpell(), goblin);
20-
goblin.printStatus();
21-
22-
wizard.castSpell(new InvisibilitySpell(), goblin);
23-
goblin.printStatus();
24-
wizard.undoLastSpell();
25-
goblin.printStatus();
20+
wizard.castSpell(new InvisibilitySpell(), goblin);
21+
goblin.printStatus();
22+
wizard.undoLastSpell();
23+
goblin.printStatus();
2624
}
2725
}
Lines changed: 17 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,25 @@
11
package com.iluwatar;
22

33
/**
4-
*
5-
* With Composite we can treat tree hierarchies of objects
6-
* with uniform interface (LetterComposite). In this example
7-
* we have sentences composed of words composed of letters.
4+
*
5+
* With Composite we can treat tree hierarchies of objects with uniform
6+
* interface (LetterComposite). In this example we have sentences composed of
7+
* words composed of letters.
88
*
99
*/
10-
public class App
11-
{
12-
public static void main( String[] args )
13-
{
14-
System.out.println("Message from the orcs: ");
15-
16-
LetterComposite orcMessage = new Messenger().messageFromOrcs();
17-
orcMessage.print();
10+
public class App {
11+
12+
public static void main(String[] args) {
13+
System.out.println("Message from the orcs: ");
14+
15+
LetterComposite orcMessage = new Messenger().messageFromOrcs();
16+
orcMessage.print();
17+
18+
System.out.println("\n");
19+
20+
System.out.println("Message from the elves: ");
1821

19-
System.out.println("\n");
20-
21-
System.out.println("Message from the elves: ");
22-
23-
LetterComposite elfMessage = new Messenger().messageFromElves();
24-
elfMessage.print();
22+
LetterComposite elfMessage = new Messenger().messageFromElves();
23+
elfMessage.print();
2524
}
2625
}
Lines changed: 16 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,24 @@
11
package com.iluwatar;
22

33
/**
4-
*
5-
* Decorator pattern is more flexible alternative to
6-
* subclassing. The decorator class implements the same
7-
* interface as the target and uses composition to
4+
*
5+
* Decorator pattern is more flexible alternative to subclassing. The decorator
6+
* class implements the same interface as the target and uses composition to
87
* "decorate" calls to the target.
98
*
109
*/
11-
public class App
12-
{
13-
public static void main( String[] args )
14-
{
15-
16-
System.out.println("A simple looking troll approaches.");
17-
Hostile troll = new Troll();
18-
troll.attack();
19-
troll.fleeBattle();
20-
21-
System.out.println("\nA smart looking troll surprises you.");
22-
Hostile smart = new SmartTroll(new Troll());
23-
smart.attack();
24-
smart.fleeBattle();
10+
public class App {
11+
12+
public static void main(String[] args) {
13+
14+
System.out.println("A simple looking troll approaches.");
15+
Hostile troll = new Troll();
16+
troll.attack();
17+
troll.fleeBattle();
18+
19+
System.out.println("\nA smart looking troll surprises you.");
20+
Hostile smart = new SmartTroll(new Troll());
21+
smart.attack();
22+
smart.fleeBattle();
2523
}
2624
}

0 commit comments

Comments
 (0)