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

View File

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

View File

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

View File

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

View File

@ -24,8 +24,6 @@ public class Mjollnir extends FlyingMagicWeaponImpl {
@Override
public void flyImp() {
System.out
.println("Mjollnir hits the enemy in the air and returns back to the owner's hand");
System.out.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() {
System.out.println("Stormbringer devours the enemy's soul");
}
}