package bridge_pattern;
public abstract class Implementor {
public abstract void Operation();
}
package bridge_pattern;
public class ConcreteImplementorA extends Implementor{
@Override
public void Operation() {
System.out.println("THe concrete method A is executing.");
}
}
package bridge_pattern;
public class ConcreteImplementorB extends Implementor{
@Override
public void Operation() {
System.out.println("THe concrete method B is executing.");
}
}
package bridge_pattern;
public class Abstraction {
protected Implementor implementor;
public void SetImplementor(Implementor implementor) {
this.implementor = implementor;
}
public void Operation() {
implementor.Operation();
}
}
package bridge_pattern;
public class RefinedAbstractionA extends Abstraction{
@Override
public void Operation() {
System.out.println("The current class is A.");
implementor.Operation();
}
}
package bridge_pattern;
public class RefinedAbstractionB extends Abstraction{
@Override
public void Operation() {
System.out.println("The current class is B.");
implementor.Operation();
}
}
package bridge_pattern;
public class Main {
public static void main(String args[]) {
Abstraction ab =new RefinedAbstractionA();
//Abstraction ab =new RefinedAbstractionB();
ab.SetImplementor(new ConcreteImplementorA());
ab.Operation();
ab.SetImplementor(new ConcreteImplementorB());
ab.Operation();
}
}
/*
* Composition is stronger than Aggregation.
* Swallow composite Wing.
* GooseGroup aggregate Swallow.
* The different is life cycle.
* The composition at the level of abstraction decouple the system
* and makes it more flexible.
*/
This is a general introduction to the 23 design patterns:
https://blog.youkuaiyun.com/GZHarryAnonymous/article/details/81567214
See more source code:[GZHarryAnonymous](https://github.com/GZHarryAnonymous/Design_Pattern)