forked from iluwatar/java-design-patterns
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Formatted all files to the same standard
- Loading branch information
Showing
151 changed files
with
952 additions
and
870 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. | ||
* | ||
* | ||
*/ | ||
public class App { | ||
|
||
public static void main(String[] args) { | ||
createKingdom(new ElfKingdomFactory()); | ||
createKingdom(new OrcKingdomFactory()); | ||
} | ||
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); | ||
} | ||
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); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,5 +6,5 @@ public class ElfArmy implements Army { | |
public String toString() { | ||
return "This is the Elven Army!"; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,5 +6,5 @@ public class ElfCastle implements Castle { | |
public String toString() { | ||
return "This is the Elven castle!"; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,5 +6,5 @@ public class ElfKing implements King { | |
public String toString() { | ||
return "This is the Elven king!"; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,7 +3,7 @@ | |
/** | ||
* | ||
* Concrete factory. | ||
* | ||
* | ||
*/ | ||
public class ElfKingdomFactory implements KingdomFactory { | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,5 +6,5 @@ public class OrcArmy implements Army { | |
public String toString() { | ||
return "This is the Orcish Army!"; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,5 +6,5 @@ public class OrcCastle implements Castle { | |
public String toString() { | ||
return "This is the Orcish castle!"; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,5 +6,5 @@ public class OrcKing implements King { | |
public String toString() { | ||
return "This is the Orc king!"; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,7 +3,7 @@ | |
/** | ||
* | ||
* Concrete factory. | ||
* | ||
* | ||
*/ | ||
public class OrcKingdomFactory implements KingdomFactory { | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +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). | ||
* | ||
* | ||
*/ | ||
public class App { | ||
|
||
public static void main(String[] args) { | ||
GnomeEngineeringManager manager = new GnomeEngineeringManager(); | ||
manager.operateDevice(); | ||
} | ||
public static void main(String[] args) { | ||
GnomeEngineeringManager manager = new GnomeEngineeringManager(); | ||
manager.operateDevice(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,10 +3,10 @@ | |
/** | ||
* | ||
* Engineers can operate devices. | ||
* | ||
* | ||
*/ | ||
public interface Engineer { | ||
|
||
void operateDevice(); | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,32 +1,35 @@ | ||
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. | ||
* | ||
* | ||
*/ | ||
public class App { | ||
|
||
public static void main(String[] args) { | ||
BlindingMagicWeapon blindingMagicWeapon = new BlindingMagicWeapon(new Excalibur()); | ||
blindingMagicWeapon.wield(); | ||
blindingMagicWeapon.blind(); | ||
blindingMagicWeapon.swing(); | ||
blindingMagicWeapon.unwield(); | ||
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(); | ||
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(); | ||
SoulEatingMagicWeapon soulEatingMagicWeapon = new SoulEatingMagicWeapon( | ||
new Stormbringer()); | ||
soulEatingMagicWeapon.wield(); | ||
soulEatingMagicWeapon.swing(); | ||
soulEatingMagicWeapon.eatSoul(); | ||
soulEatingMagicWeapon.unwield(); | ||
|
||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.