Reference Documentation:
1. Design mode-the basis of reusable object-oriented software
2.http://blog.csdn.net/hguisu/article/details/7529194 (design mode (vi) bridge mode bridges (structural type))
Bridging mode (bridge) (object-structured mode)
Theoretical knowledge, you can refer to the reference document.
Look at the structure of bridge:
The structure of the window example that is spoken in the book:
Code implementation:
Brushpenabstraction.java:
Package com.rick.designpattern.bridge2;
/**
* Created by MyPC on 2017/6/26.
*/Public
abstract class Brushpenabstraction {
protected implementorcolor implementorcolor;
public void Setimplementorcolor (Implementorcolor implementorcolor) {
this.implementorcolor = Implementorcolor;
} Public
abstract void Operationdraw ();
}
Bigbrushpenrefinedabstraction.java:
Package com.rick.designpattern.bridge2;
/**
* Created by MyPC on 2017/6/26.
*/Public
class Bigbrushpenrefinedabstraction extends Brushpenabstraction {
@Override public
Void Operationdraw () {
System.out.println ("Big and" + implementorcolor.bepaint () + "drawing");
}
}
Middlebrushpenrefinedabstraction.java:
Package com.rick.designpattern.bridge2;
/**
* Created by MyPC on 2017/6/26.
*/Public
class Middlebrushpenrefinedabstraction extends Brushpenabstraction {
@Override public
Void Operationdraw () {
System.out.println ("Middle and" + implementorcolor.bepaint () + "drawing");
}
}
Smallbrushpenrefinedabstraction.java:
Package com.rick.designpattern.bridge2;
/**
* Created by MyPC on 2017/6/26.
*/Public
class Smallbrushpenrefinedabstraction extends Brushpenabstraction {
@Override public
Void Operationdraw () {
System.out.println ("Small and" + implementorcolor.bepaint () + "drawing");
}
}
Implementorcolor.java:
Package com.rick.designpattern.bridge2;
/**
* Created by MyPC on 2017/6/26.
*/Public
class Implementorcolor {
protected String color;
Public String Bepaint () {
return color;
}
}
Concreteimplementorblack.java:
Package com.rick.designpattern.bridge2;
/**
* Created by MyPC on 2017/6/26.
*
/public class Concreteimplementorblack extends Implementorcolor {public
concreteimplementorblack () {
This.color = "Black";
}
}
Concreteimplementorblue.java:
Package com.rick.designpattern.bridge2;
/**
* Created by MyPC on 2017/6/26.
*
/public class Concreteimplementorblue extends Implementorcolor {public
concreteimplementorblue () {
This.color = "Blue";
}
}
Concreteimplementorgreen.java:
Package com.rick.designpattern.bridge2;
/**
* Created by MyPC on 2017/6/26.
*
/public class Concreteimplementorgreen extends Implementorcolor {public
concreteimplementorgreen () {
This.color = "green";
}
}
Concreteimplementorred.java:
Package com.rick.designpattern.bridge2;
/**
* Created by MyPC on 2017/6/26.
*
/public class Concreteimplementorred extends Implementorcolor {public
concreteimplementorred () {
This.color = "Red";
}
}
Concreteimplementorwhite.java:
Package com.rick.designpattern.bridge2;
/**
* Created by MyPC on 2017/6/26.
*
/public class Concreteimplementorwhite extends Implementorcolor {public
concreteimplementorwhite () {
This.color = "white";
}
}
Brushpenfactory.java:
Package com.rick.designpattern.bridge2;
/**
* Created by MyPC on 2017/6/26.
*/Public
class Brushpenfactory {
private static brushpenfactory _instance;
Private Brushpenabstraction _brushpenabstraction;
Private Brushpenfactory () {
} public
static Brushpenfactory instance () {
if (null = = _instance) {
_ Instance = new Brushpenfactory ();
}
return _instance;
}
Public Brushpenabstraction Makebrushpen () {
_brushpenabstraction = new Smallbrushpenrefinedabstraction ();
_brushpenabstraction.setimplementorcolor (New Concreteimplementorblack ());
return _brushpenabstraction;
}
}
Client.java:
Package com.rick.designpattern.bridge2;
/**
* Created by MyPC on 2017/6/26.
*/Public
class Client {public
static void Main (string[] args) {
brushpenfactory.instance (). Makebrushpen ( ). Operationdraw ();
}
}