# bridge pattern -- 桥接模式

Bridge模式又称为Handle/Body模式。

1 class MichelinWheel
2 {
3     public:
4         MichelinWheel(int q,...);
6     private:
7         int qulity;
8         ....
9 };
10 MichelinWheel::MichelinWheel( int q,....)
11 :quilty(q)
12 {}
14 {
15     //经过一些列因素和公式得出该轮胎的负载能力
16     ...
18 }
19
20 class BenzCar
21 {
22     public:
23         int getDistance( )
24     private:
25         MichelinWheel* wheel
26         int speed
27 };
28 BenzCar::BenzCar(MichelinWheel* w)
29 {
30     wheel=w;
31 }
32 BenzCar::getDistance ( )
33 {
34     carSpeed=speed;
35     //经过一些列因素和公式得出汽车在某个速度的制动距离
36     ...
37     return distance
38 }

1 class MichelinWheel
2 {
3     public:
4         MichelinWheel(int q,...);
5         int  getFriction( );
6     private:
7         int qulity;
8         ....
9 };
10 MichelinWheel::MichelinWheel( int q,....)
11 :quilty(q)
12 {}
13 int MichelinWheel::getFriction( )
14 {
15     //经过一些列因素和公式得出该轮胎的摩擦力
16     ...
17     return friction;
18 }
19
20 class Car
21 {
22     vritual int getDistance( )=0;
23 };
24
25 class BenzCar:public Car
26 {
27     public:
28         int getDistance( )
29     private:
30         MichelinWheel* wheel
31         int speed
32 };
33 BenzCar::BenzCar(MichelinWheel* w)
34 {
35     wheel=w;
36 }
37 BenzCar::getDistance ( )
38 {
39     carSpeed=speed;
40     //经过一些列因素和公式得出汽车在某个速度的制动距离
41     ...
42     return distance
43 }

1 class Wheel
2 {
3     public:
4         virtual int getFriction( )=0;
5 };
6
7 class MichelinWheel:public Wheel
8 {
9     public:
10         MichelinWheel(int q,...);
11         int  getFriction( );
12     private:
13         int qulity;
14         ....
15 };
16 MichelinWheel::MichelinWheel( int q,....)
17 :quilty(q)
18 {}
19 int MichelinWheel::getFriction( )
20 {
21     //经过一些列因素和公式得出该轮胎的摩擦力
22     ...
23     return  friction ;
24 }
25
26 class Car
27 {
28     vritual int getDistance( )=0;
29 };
30
31 class BenzCar:public Car
32 {
33     public:
34         int getDistance( )
35     private:
36         Wheel* wheel
37         int speed
38 };
39 BenzCar::BenzCar(Wheel* w)
40 {
41     wheel=w;
42 }
43 BenzCar::getDistance ( )
44 {
45     carSpeed=speed;
46     //经过一些列因素和公式得出汽车在某个速度的制动距离
47     ...
48     return distance
49 }

posted @ 2012-12-18 00:55  胡佳180815  阅读(1622)  评论(3编辑  收藏  举报