Reformat bridge design pattern - Issue #224

This commit is contained in:
Ankur Kaushal
2015-11-01 17:43:54 -05:00
parent 16a8c85af6
commit e7b6542134
13 changed files with 161 additions and 171 deletions

View File

@ -2,41 +2,38 @@ package com.iluwatar.bridge;
/** /**
* *
* The Bridge pattern can also be thought of as two layers of abstraction. With Bridge, * The Bridge pattern can also be thought of as two layers of abstraction. With Bridge, you can
* you can decouple an abstraction from its implementation so that the two can vary independently. * decouple an abstraction from its implementation so that the two can vary independently.
* <p> * <p>
* In Bridge pattern both abstraction ({@link MagicWeapon}) and implementation * In Bridge pattern both abstraction ({@link MagicWeapon}) and implementation (
* ({@link MagicWeaponImpl}) have their own class hierarchies. The interface of the * {@link MagicWeaponImpl}) have their own class hierarchies. The interface of the implementations
* implementations can be changed without affecting the clients. * can be changed without affecting the clients.
* *
*/ */
public class App { public class App {
/** /**
* Program entry point * Program entry point
*
* @param args command line args * @param args command line args
*/ */
public static void main(String[] args) { public static void main(String[] args) {
BlindingMagicWeapon blindingMagicWeapon = new BlindingMagicWeapon( BlindingMagicWeapon blindingMagicWeapon = new BlindingMagicWeapon(new Excalibur());
new Excalibur());
blindingMagicWeapon.wield(); blindingMagicWeapon.wield();
blindingMagicWeapon.blind(); blindingMagicWeapon.blind();
blindingMagicWeapon.swing(); blindingMagicWeapon.swing();
blindingMagicWeapon.unwield(); blindingMagicWeapon.unwield();
FlyingMagicWeapon flyingMagicWeapon = new FlyingMagicWeapon( FlyingMagicWeapon flyingMagicWeapon = new FlyingMagicWeapon(new Mjollnir());
new Mjollnir());
flyingMagicWeapon.wield(); flyingMagicWeapon.wield();
flyingMagicWeapon.fly(); flyingMagicWeapon.fly();
flyingMagicWeapon.swing(); flyingMagicWeapon.swing();
flyingMagicWeapon.unwield(); flyingMagicWeapon.unwield();
SoulEatingMagicWeapon soulEatingMagicWeapon = new SoulEatingMagicWeapon( SoulEatingMagicWeapon soulEatingMagicWeapon = new SoulEatingMagicWeapon(new Stormbringer());
new Stormbringer());
soulEatingMagicWeapon.wield(); soulEatingMagicWeapon.wield();
soulEatingMagicWeapon.swing(); soulEatingMagicWeapon.swing();
soulEatingMagicWeapon.eatSoul(); soulEatingMagicWeapon.eatSoul();
soulEatingMagicWeapon.unwield(); soulEatingMagicWeapon.unwield();
} }
} }

View File

@ -34,5 +34,4 @@ public class BlindingMagicWeapon extends MagicWeapon {
public void blind() { public void blind() {
getImp().blindImp(); getImp().blindImp();
} }
} }

View File

@ -24,8 +24,6 @@ public class Excalibur extends BlindingMagicWeaponImpl {
@Override @Override
public void blindImp() { public void blindImp() {
System.out System.out.println("bright light streams from Excalibur blinding the enemy");
.println("bright light streams from Excalibur blinding the enemy");
} }
} }

View File

@ -22,5 +22,4 @@ public abstract class MagicWeapon {
public MagicWeaponImpl getImp() { public MagicWeaponImpl getImp() {
return imp; return imp;
} }
} }

View File

@ -24,8 +24,6 @@ public class Mjollnir extends FlyingMagicWeaponImpl {
@Override @Override
public void flyImp() { public void flyImp() {
System.out System.out.println("Mjollnir hits the enemy in the air and returns back to the owner's hand");
.println("Mjollnir hits the enemy in the air and returns back to the owner's hand");
} }
} }

View File

@ -26,5 +26,4 @@ public class Stormbringer extends SoulEatingMagicWeaponImpl {
public void eatSoulImp() { public void eatSoulImp() {
System.out.println("Stormbringer devours the enemy's soul"); System.out.println("Stormbringer devours the enemy's soul");
} }
} }