Just formatting App classes to be like the other class files on the project
This commit is contained in:
parent
52f0923df9
commit
bde5b343d0
@ -2,17 +2,17 @@ package com.iluwatar;
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* The essence of the Abstract Factory pattern is a factory interface (KingdomFactory)
|
* The essence of the Abstract Factory pattern is a factory interface
|
||||||
* and its implementations (ElfKingdomFactory, OrcKingdomFactory).
|
* (KingdomFactory) and its implementations (ElfKingdomFactory,
|
||||||
|
* OrcKingdomFactory).
|
||||||
*
|
*
|
||||||
* The example uses both concrete implementations to create a king, a castle and an
|
* The example uses both concrete implementations to create a king, a castle and
|
||||||
* army.
|
* an army.
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public class App
|
public class App {
|
||||||
{
|
|
||||||
public static void main( String[] args )
|
public static void main(String[] args) {
|
||||||
{
|
|
||||||
createKingdom(new ElfKingdomFactory());
|
createKingdom(new ElfKingdomFactory());
|
||||||
createKingdom(new OrcKingdomFactory());
|
createKingdom(new OrcKingdomFactory());
|
||||||
}
|
}
|
||||||
|
@ -2,21 +2,19 @@ package com.iluwatar;
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* There are two variations of the Adapter pattern: The
|
* There are two variations of the Adapter pattern: The class adapter implements
|
||||||
* class adapter implements the adaptee's interface whereas
|
* the adaptee's interface whereas the object adapter uses composition to
|
||||||
* the object adapter uses composition to contain the adaptee
|
* contain the adaptee in the adapter object. This example uses the object
|
||||||
* in the adapter object. This example uses the object adapter
|
* adapter approach.
|
||||||
* approach.
|
|
||||||
*
|
*
|
||||||
* The Adapter (GnomeEngineer) converts the interface of the
|
* The Adapter (GnomeEngineer) converts the interface of the target class
|
||||||
* target class (GoblinGlider) into a suitable one expected
|
* (GoblinGlider) into a suitable one expected by the client
|
||||||
* by the client (GnomeEngineeringManager).
|
* (GnomeEngineeringManager).
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public class App
|
public class App {
|
||||||
{
|
|
||||||
public static void main( String[] args )
|
public static void main(String[] args) {
|
||||||
{
|
|
||||||
GnomeEngineeringManager manager = new GnomeEngineeringManager();
|
GnomeEngineeringManager manager = new GnomeEngineeringManager();
|
||||||
manager.operateDevice();
|
manager.operateDevice();
|
||||||
}
|
}
|
||||||
|
@ -2,17 +2,14 @@ package com.iluwatar;
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* In Bridge pattern both abstraction (MagicWeapon)
|
* In Bridge pattern both abstraction (MagicWeapon) and implementation
|
||||||
* and implementation (MagicWeaponImp) have their
|
* (MagicWeaponImp) have their own class hierarchies. The interface of the
|
||||||
* own class hierarchies. The interface of the
|
* implementations can be changed without affecting the clients.
|
||||||
* implementations can be changed without affecting
|
|
||||||
* the clients.
|
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public class App
|
public class App {
|
||||||
{
|
|
||||||
public static void main( String[] args )
|
public static void main(String[] args) {
|
||||||
{
|
|
||||||
BlindingMagicWeapon blindingMagicWeapon = new BlindingMagicWeapon(new Excalibur());
|
BlindingMagicWeapon blindingMagicWeapon = new BlindingMagicWeapon(new Excalibur());
|
||||||
blindingMagicWeapon.wield();
|
blindingMagicWeapon.wield();
|
||||||
blindingMagicWeapon.blind();
|
blindingMagicWeapon.blind();
|
||||||
|
@ -4,24 +4,20 @@ import com.iluwatar.Hero.HeroBuilder;
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* This is the Builder pattern variation as described by
|
* This is the Builder pattern variation as described by Joshua Bloch in
|
||||||
* Joshua Bloch in Effective Java 2nd Edition.
|
* Effective Java 2nd Edition.
|
||||||
*
|
*
|
||||||
* We want to build Hero objects, but its construction
|
* We want to build Hero objects, but its construction is complex because of the
|
||||||
* is complex because of the many parameters needed. To
|
* many parameters needed. To aid the user we introduce HeroBuilder class.
|
||||||
* aid the user we introduce HeroBuilder class. HeroBuilder
|
* HeroBuilder takes the minimum parameters to build Hero object in its
|
||||||
* takes the minimum parameters to build Hero object in
|
* constructor. After that additional configuration for the Hero object can be
|
||||||
* its constructor. After that additional configuration
|
* done using the fluent HeroBuilder interface. When configuration is ready the
|
||||||
* for the Hero object can be done using the fluent
|
* build method is called to receive the final Hero object.
|
||||||
* HeroBuilder interface. When configuration is ready
|
|
||||||
* the build method is called to receive the final Hero
|
|
||||||
* object.
|
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public class App
|
public class App {
|
||||||
{
|
|
||||||
public static void main( String[] args )
|
public static void main(String[] args) {
|
||||||
{
|
|
||||||
|
|
||||||
Hero mage = new HeroBuilder(Profession.MAGE, "Riobard")
|
Hero mage = new HeroBuilder(Profession.MAGE, "Riobard")
|
||||||
.withHairColor(HairColor.BLACK)
|
.withHairColor(HairColor.BLACK)
|
||||||
|
@ -2,16 +2,15 @@ package com.iluwatar;
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* Chain of Responsibility organizes request handlers (RequestHandler) into
|
* Chain of Responsibility organizes request handlers (RequestHandler) into a
|
||||||
* a chain where each handler has a chance to act on the request on its
|
* chain where each handler has a chance to act on the request on its turn. In
|
||||||
* turn. In this example the king (OrcKing) makes requests and the military
|
* this example the king (OrcKing) makes requests and the military orcs
|
||||||
* orcs (OrcCommander, OrcOfficer, OrcSoldier) form the handler chain.
|
* (OrcCommander, OrcOfficer, OrcSoldier) form the handler chain.
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public class App
|
public class App {
|
||||||
{
|
|
||||||
public static void main( String[] args )
|
public static void main(String[] args) {
|
||||||
{
|
|
||||||
|
|
||||||
OrcKing king = new OrcKing();
|
OrcKing king = new OrcKing();
|
||||||
king.makeRequest(new Request(RequestType.DEFEND_CASTLE, "defend castle"));
|
king.makeRequest(new Request(RequestType.DEFEND_CASTLE, "defend castle"));
|
||||||
|
@ -2,15 +2,13 @@ package com.iluwatar;
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* In Command pattern actions are objects that can
|
* In Command pattern actions are objects that can be executed and undone. The
|
||||||
* be executed and undone. The commands in this example
|
* commands in this example are spells cast by the wizard on the goblin.
|
||||||
* are spells cast by the wizard on the goblin.
|
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public class App
|
public class App {
|
||||||
{
|
|
||||||
public static void main( String[] args )
|
public static void main(String[] args) {
|
||||||
{
|
|
||||||
Wizard wizard = new Wizard();
|
Wizard wizard = new Wizard();
|
||||||
Goblin goblin = new Goblin();
|
Goblin goblin = new Goblin();
|
||||||
|
|
||||||
|
@ -2,15 +2,14 @@ package com.iluwatar;
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* With Composite we can treat tree hierarchies of objects
|
* With Composite we can treat tree hierarchies of objects with uniform
|
||||||
* with uniform interface (LetterComposite). In this example
|
* interface (LetterComposite). In this example we have sentences composed of
|
||||||
* we have sentences composed of words composed of letters.
|
* words composed of letters.
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public class App
|
public class App {
|
||||||
{
|
|
||||||
public static void main( String[] args )
|
public static void main(String[] args) {
|
||||||
{
|
|
||||||
System.out.println("Message from the orcs: ");
|
System.out.println("Message from the orcs: ");
|
||||||
|
|
||||||
LetterComposite orcMessage = new Messenger().messageFromOrcs();
|
LetterComposite orcMessage = new Messenger().messageFromOrcs();
|
||||||
|
@ -2,16 +2,14 @@ package com.iluwatar;
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* Decorator pattern is more flexible alternative to
|
* Decorator pattern is more flexible alternative to subclassing. The decorator
|
||||||
* subclassing. The decorator class implements the same
|
* class implements the same interface as the target and uses composition to
|
||||||
* interface as the target and uses composition to
|
|
||||||
* "decorate" calls to the target.
|
* "decorate" calls to the target.
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public class App
|
public class App {
|
||||||
{
|
|
||||||
public static void main( String[] args )
|
public static void main(String[] args) {
|
||||||
{
|
|
||||||
|
|
||||||
System.out.println("A simple looking troll approaches.");
|
System.out.println("A simple looking troll approaches.");
|
||||||
Hostile troll = new Troll();
|
Hostile troll = new Troll();
|
||||||
|
@ -5,17 +5,14 @@ import java.util.concurrent.Executors;
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* In Inventory we store the items with a given size. However,
|
* In Inventory we store the items with a given size. However, we do not store
|
||||||
* we do not store more items than the inventory size. To address
|
* more items than the inventory size. To address concurrent access problems we
|
||||||
* concurrent access problems we use double checked locking to add
|
* use double checked locking to add item to inventory. In this method, the
|
||||||
* item to inventory. In this method, the thread which gets the lock
|
* thread which gets the lock first adds the item.
|
||||||
* first adds the item.
|
|
||||||
*/
|
*/
|
||||||
|
public class App {
|
||||||
|
|
||||||
public class App
|
public static void main(String[] args) {
|
||||||
{
|
|
||||||
public static void main( String[] args )
|
|
||||||
{
|
|
||||||
final Inventory inventory = new Inventory(1000);
|
final Inventory inventory = new Inventory(1000);
|
||||||
ExecutorService executorService = Executors.newFixedThreadPool(3);
|
ExecutorService executorService = Executors.newFixedThreadPool(3);
|
||||||
for (int i = 0; i < 3; i++) {
|
for (int i = 0; i < 3; i++) {
|
||||||
|
@ -2,14 +2,12 @@ package com.iluwatar;
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* Facade (DwarvenGoldmineFacade) provides simpler interface to
|
* Facade (DwarvenGoldmineFacade) provides simpler interface to subsystem.
|
||||||
* subsystem.
|
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public class App
|
public class App {
|
||||||
{
|
|
||||||
public static void main( String[] args )
|
public static void main(String[] args) {
|
||||||
{
|
|
||||||
DwarvenGoldmineFacade facade = new DwarvenGoldmineFacade();
|
DwarvenGoldmineFacade facade = new DwarvenGoldmineFacade();
|
||||||
facade.startNewDay();
|
facade.startNewDay();
|
||||||
facade.digOutGold();
|
facade.digOutGold();
|
||||||
|
@ -2,16 +2,14 @@ package com.iluwatar;
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* In Factory Method we have an interface (Blacksmith) with a
|
* In Factory Method we have an interface (Blacksmith) with a method for
|
||||||
* method for creating objects (manufactureWeapon). The concrete
|
* creating objects (manufactureWeapon). The concrete subclasses (OrcBlacksmith,
|
||||||
* subclasses (OrcBlacksmith, ElfBlacksmith) then override the
|
* ElfBlacksmith) then override the method to produce objects of their liking.
|
||||||
* method to produce objects of their liking.
|
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public class App
|
public class App {
|
||||||
{
|
|
||||||
public static void main( String[] args )
|
public static void main(String[] args) {
|
||||||
{
|
|
||||||
Blacksmith blacksmith;
|
Blacksmith blacksmith;
|
||||||
Weapon weapon;
|
Weapon weapon;
|
||||||
|
|
||||||
|
@ -2,15 +2,14 @@ package com.iluwatar;
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* Flyweight (PotionFactory) is useful when there is plethora of
|
* Flyweight (PotionFactory) is useful when there is plethora of objects
|
||||||
* objects (Potion). It provides means to decrease resource usage
|
* (Potion). It provides means to decrease resource usage by sharing object
|
||||||
* by sharing object instances.
|
* instances.
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public class App
|
public class App {
|
||||||
{
|
|
||||||
public static void main( String[] args )
|
public static void main(String[] args) {
|
||||||
{
|
|
||||||
AlchemistShop alchemistShop = new AlchemistShop();
|
AlchemistShop alchemistShop = new AlchemistShop();
|
||||||
alchemistShop.enumerate();
|
alchemistShop.enumerate();
|
||||||
}
|
}
|
||||||
|
@ -4,12 +4,11 @@ import java.util.Stack;
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* Interpreter pattern breaks sentences into expressions (Expression)
|
* Interpreter pattern breaks sentences into expressions (Expression) that can
|
||||||
* that can be evaluated and as a whole form the result.
|
* be evaluated and as a whole form the result.
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public class App
|
public class App {
|
||||||
{
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
@ -17,8 +16,7 @@ public class App
|
|||||||
* This sample uses postfix, where operator comes after the operands
|
* This sample uses postfix, where operator comes after the operands
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public static void main( String[] args )
|
public static void main(String[] args) {
|
||||||
{
|
|
||||||
String tokenString = "4 3 2 - 1 + *";
|
String tokenString = "4 3 2 - 1 + *";
|
||||||
Stack<Expression> stack = new Stack<>();
|
Stack<Expression> stack = new Stack<>();
|
||||||
|
|
||||||
@ -46,11 +44,12 @@ public class App
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static boolean isOperator(String s) {
|
public static boolean isOperator(String s) {
|
||||||
if (s.equals("+") || s.equals("-") || s.equals("*"))
|
if (s.equals("+") || s.equals("-") || s.equals("*")) {
|
||||||
return true;
|
return true;
|
||||||
else
|
} else {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public static Expression getOperatorInstance(String s, Expression left,
|
public static Expression getOperatorInstance(String s, Expression left,
|
||||||
Expression right) {
|
Expression right) {
|
||||||
|
@ -2,15 +2,14 @@ package com.iluwatar;
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* Iterator (ItemIterator) adds abstraction layer on top of a
|
* Iterator (ItemIterator) adds abstraction layer on top of a collection
|
||||||
* collection (TreasureChest). This way the collection can change
|
* (TreasureChest). This way the collection can change its internal
|
||||||
* its internal implementation without affecting its clients.
|
* implementation without affecting its clients.
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public class App
|
public class App {
|
||||||
{
|
|
||||||
public static void main( String[] args )
|
public static void main(String[] args) {
|
||||||
{
|
|
||||||
TreasureChest chest = new TreasureChest();
|
TreasureChest chest = new TreasureChest();
|
||||||
|
|
||||||
ItemIterator ringIterator = chest.Iterator(ItemType.RING);
|
ItemIterator ringIterator = chest.Iterator(ItemType.RING);
|
||||||
|
@ -2,15 +2,13 @@ package com.iluwatar;
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* Mediator encapsulates how set of objects (PartyMember) interact.
|
* Mediator encapsulates how set of objects (PartyMember) interact. Instead of
|
||||||
* Instead of referring to each other directly they
|
* referring to each other directly they use the mediator (Party) interface.
|
||||||
* use the mediator (Party) interface.
|
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public class App
|
public class App {
|
||||||
{
|
|
||||||
public static void main( String[] args )
|
public static void main(String[] args) {
|
||||||
{
|
|
||||||
Party party = new PartyImpl();
|
Party party = new PartyImpl();
|
||||||
Hobbit hobbit = new Hobbit();
|
Hobbit hobbit = new Hobbit();
|
||||||
Wizard wizard = new Wizard();
|
Wizard wizard = new Wizard();
|
||||||
|
@ -4,17 +4,14 @@ import java.util.Stack;
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* Memento pattern is for storing and restoring object
|
* Memento pattern is for storing and restoring object state. The object (Star)
|
||||||
* state. The object (Star) gives out a "memento"
|
* gives out a "memento" (StarMemento) that contains the state of the object.
|
||||||
* (StarMemento) that contains the state of the object.
|
* Later on the memento can be set back to the object restoring the state.
|
||||||
* Later on the memento can be set back to the object
|
|
||||||
* restoring the state.
|
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public class App
|
public class App {
|
||||||
{
|
|
||||||
public static void main( String[] args )
|
public static void main(String[] args) {
|
||||||
{
|
|
||||||
Stack<StarMemento> states = new Stack<>();
|
Stack<StarMemento> states = new Stack<>();
|
||||||
|
|
||||||
Star star = new Star(StarType.SUN, 10000000, 500000);
|
Star star = new Star(StarType.SUN, 10000000, 500000);
|
||||||
|
@ -2,15 +2,13 @@ package com.iluwatar;
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* Observer pattern defines one-to-many relationship
|
* Observer pattern defines one-to-many relationship between objects. The target
|
||||||
* between objects. The target object sends change
|
* object sends change notifications to its registered observers.
|
||||||
* notifications to its registered observers.
|
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public class App
|
public class App {
|
||||||
{
|
|
||||||
public static void main( String[] args )
|
public static void main(String[] args) {
|
||||||
{
|
|
||||||
|
|
||||||
Weather weather = new Weather();
|
Weather weather = new Weather();
|
||||||
weather.addObserver(new Orcs());
|
weather.addObserver(new Orcs());
|
||||||
|
@ -2,15 +2,14 @@ package com.iluwatar;
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* In Prototype we have a factory class (HeroFactoryImpl) producing
|
* In Prototype we have a factory class (HeroFactoryImpl) producing objects by
|
||||||
* objects by cloning existing ones. In this example the factory's
|
* cloning existing ones. In this example the factory's prototype objects are
|
||||||
* prototype objects are given as constructor parameters.
|
* given as constructor parameters.
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public class App
|
public class App {
|
||||||
{
|
|
||||||
public static void main( String[] args )
|
public static void main(String[] args) {
|
||||||
{
|
|
||||||
HeroFactory factory;
|
HeroFactory factory;
|
||||||
Mage mage;
|
Mage mage;
|
||||||
Warlord warlord;
|
Warlord warlord;
|
||||||
|
@ -2,14 +2,12 @@ package com.iluwatar;
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* Proxy (WizardTowerProxy) controls access to the
|
* Proxy (WizardTowerProxy) controls access to the actual object (WizardTower).
|
||||||
* actual object (WizardTower).
|
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public class App
|
public class App {
|
||||||
{
|
|
||||||
public static void main( String[] args )
|
public static void main(String[] args) {
|
||||||
{
|
|
||||||
|
|
||||||
WizardTowerProxy tower = new WizardTowerProxy();
|
WizardTowerProxy tower = new WizardTowerProxy();
|
||||||
tower.enter(new Wizard("Red wizard"));
|
tower.enter(new Wizard("Red wizard"));
|
||||||
|
@ -2,14 +2,13 @@ package com.iluwatar;
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* Singleton pattern ensures that the class (IvoryTower) can have only
|
* Singleton pattern ensures that the class (IvoryTower) can have only one
|
||||||
* one existing instance and provides global access to that instance.
|
* existing instance and provides global access to that instance.
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public class App
|
public class App {
|
||||||
{
|
|
||||||
public static void main( String[] args )
|
public static void main(String[] args) {
|
||||||
{
|
|
||||||
|
|
||||||
IvoryTower ivoryTower1 = IvoryTower.getInstance();
|
IvoryTower ivoryTower1 = IvoryTower.getInstance();
|
||||||
IvoryTower ivoryTower2 = IvoryTower.getInstance();
|
IvoryTower ivoryTower2 = IvoryTower.getInstance();
|
||||||
|
@ -2,16 +2,14 @@ package com.iluwatar;
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* In State pattern the object (Mammoth) has internal
|
* In State pattern the object (Mammoth) has internal state object (State) that
|
||||||
* state object (State) that defines the current
|
* defines the current behavior. The state object can be changed to alter the
|
||||||
* behavior. The state object can be changed
|
* behavior.
|
||||||
* to alter the behavior.
|
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public class App
|
public class App {
|
||||||
{
|
|
||||||
public static void main( String[] args )
|
public static void main(String[] args) {
|
||||||
{
|
|
||||||
|
|
||||||
Mammoth mammoth = new Mammoth();
|
Mammoth mammoth = new Mammoth();
|
||||||
mammoth.observe();
|
mammoth.observe();
|
||||||
|
@ -2,14 +2,13 @@ package com.iluwatar;
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* Strategy (DragonSlayingStrategy) encapsulates the algorithm to use.
|
* Strategy (DragonSlayingStrategy) encapsulates the algorithm to use. The
|
||||||
* The object (DragonSlayer) can alter its behavior by changing its strategy.
|
* object (DragonSlayer) can alter its behavior by changing its strategy.
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public class App
|
public class App {
|
||||||
{
|
|
||||||
public static void main( String[] args )
|
public static void main(String[] args) {
|
||||||
{
|
|
||||||
System.out.println("Green dragon spotted ahead!");
|
System.out.println("Green dragon spotted ahead!");
|
||||||
DragonSlayer dragonSlayer = new DragonSlayer(new MeleeStrategy());
|
DragonSlayer dragonSlayer = new DragonSlayer(new MeleeStrategy());
|
||||||
dragonSlayer.goToBattle();
|
dragonSlayer.goToBattle();
|
||||||
|
@ -2,15 +2,13 @@ package com.iluwatar;
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* Template Method (StealingMethod) defines skeleton for the
|
* Template Method (StealingMethod) defines skeleton for the algorithm and
|
||||||
* algorithm and subclasses (HitAndRunMethod, SubtleMethod)
|
* subclasses (HitAndRunMethod, SubtleMethod) fill in the blanks.
|
||||||
* fill in the blanks.
|
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public class App
|
public class App {
|
||||||
{
|
|
||||||
public static void main( String[] args )
|
public static void main(String[] args) {
|
||||||
{
|
|
||||||
HalflingThief thief = new HalflingThief(new HitAndRunMethod());
|
HalflingThief thief = new HalflingThief(new HitAndRunMethod());
|
||||||
thief.steal();
|
thief.steal();
|
||||||
thief.changeMethod(new SubtleMethod());
|
thief.changeMethod(new SubtleMethod());
|
||||||
|
@ -2,15 +2,14 @@ package com.iluwatar;
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* Visitor pattern defines mechanism to apply operations
|
* Visitor pattern defines mechanism to apply operations (UnitVisitor) on nodes
|
||||||
* (UnitVisitor) on nodes (Unit) in hierarchy. New operations
|
* (Unit) in hierarchy. New operations can be added without altering the node
|
||||||
* can be added without altering the node interface.
|
* interface.
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public class App
|
public class App {
|
||||||
{
|
|
||||||
public static void main( String[] args )
|
public static void main(String[] args) {
|
||||||
{
|
|
||||||
|
|
||||||
Commander commander = new Commander(
|
Commander commander = new Commander(
|
||||||
new Sergeant(new Soldier(), new Soldier(), new Soldier()),
|
new Sergeant(new Soldier(), new Soldier(), new Soldier()),
|
||||||
|
Loading…
x
Reference in New Issue
Block a user