forked from luisburgos/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.
- Loading branch information
Showing
14 changed files
with
156 additions
and
1 deletion.
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
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 |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package bridge.examples.workshop; | ||
|
||
public class Assemble implements Workshop { | ||
|
||
@Override | ||
public void work() { | ||
System.out.print(" And"); | ||
System.out.println(" Assembled."); | ||
} | ||
} |
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 |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package bridge.examples.workshop; | ||
|
||
public class Bike extends Vehicle { | ||
|
||
public Bike(Workshop workShop1, Workshop workShop2) { | ||
super(workShop1, workShop2); | ||
} | ||
|
||
@Override | ||
public void manufacture() { | ||
System.out.print("Bike "); | ||
workShop1.work(); | ||
workShop2.work(); | ||
} | ||
} |
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 |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package bridge.examples.workshop; | ||
|
||
public class Car extends Vehicle { | ||
|
||
public Car(Workshop workShop1, Workshop workShop2){ | ||
super(workShop1, workShop2); | ||
} | ||
|
||
@Override | ||
public void manufacture() { | ||
System.out.print("Car "); | ||
workShop1.work(); | ||
workShop2.work(); | ||
} | ||
} |
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 |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package bridge.examples.workshop; | ||
|
||
public class Client { | ||
|
||
public static void main(String[] args) { | ||
Vehicle vehicle1 = new Car(new Produce(), new Assemble()); | ||
vehicle1.manufacture(); | ||
Vehicle vehicle2 = new Bike(new Produce(), new Assemble()); | ||
vehicle2.manufacture(); | ||
} | ||
} |
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 |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package bridge.examples.workshop; | ||
|
||
public class Produce implements Workshop { | ||
|
||
@Override | ||
public void work() { | ||
System.out.print("Produced"); | ||
} | ||
} |
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 |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package bridge.examples.workshop; | ||
|
||
public abstract class Vehicle { | ||
|
||
protected Workshop workShop1; | ||
protected Workshop workShop2; | ||
|
||
protected Vehicle(Workshop workShop1, Workshop workShop2) { | ||
this.workShop1 = workShop1; | ||
this.workShop2 = workShop2; | ||
} | ||
|
||
abstract public void manufacture(); | ||
} |
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 |
---|---|---|
@@ -0,0 +1,5 @@ | ||
package bridge.examples.workshop; | ||
|
||
public interface Workshop { | ||
abstract public void work(); | ||
} |
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 |
---|---|---|
@@ -0,0 +1,5 @@ | ||
package bridge.pattern; | ||
|
||
public interface Abstraction { | ||
void operacion(); | ||
} |
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 |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package bridge.pattern; | ||
|
||
public class Client { | ||
|
||
public static void main(String[] args) { | ||
|
||
Abstraction[] abstracciones = new Abstraction[2]; | ||
abstracciones[0] = new RefinedAbstraction(new ImplementorA()); | ||
abstracciones[1] = new RefinedAbstraction(new ImplementorB()); | ||
|
||
for(Abstraction abstraccion:abstracciones) { | ||
abstraccion.operacion(); | ||
} | ||
} | ||
} |
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 |
---|---|---|
@@ -0,0 +1,5 @@ | ||
package bridge.pattern; | ||
|
||
public interface Implementor { | ||
void operacion(); | ||
} |
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 |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package bridge.pattern; | ||
|
||
public class ImplementorA implements Implementor{ | ||
|
||
public void operacion() { | ||
System.out.println("Esta es la implementacion A"); | ||
} | ||
} |
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 |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package bridge.pattern; | ||
|
||
public class ImplementorB implements Implementor{ | ||
|
||
public void operacion() { | ||
System.out.println("Esta es la implementacion B"); | ||
} | ||
|
||
} |
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 |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package bridge.pattern; | ||
|
||
public class RefinedAbstraction implements Abstraction{ | ||
|
||
private Implementor implementador; | ||
|
||
public RefinedAbstraction(Implementor implementador){ | ||
this.implementador = implementador; | ||
} | ||
public void operacion(){ | ||
implementador.operacion(); | ||
} | ||
|
||
} |