Reformat bridge design pattern - Issue #224
This commit is contained in:
@ -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();
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -34,5 +34,4 @@ public class BlindingMagicWeapon extends MagicWeapon {
|
|||||||
public void blind() {
|
public void blind() {
|
||||||
getImp().blindImp();
|
getImp().blindImp();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -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");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -22,5 +22,4 @@ public abstract class MagicWeapon {
|
|||||||
public MagicWeaponImpl getImp() {
|
public MagicWeaponImpl getImp() {
|
||||||
return imp;
|
return imp;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -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");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -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");
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user