The brainless Bridge Model-I don't understand ..

Source: Internet
Author: User

I looked at it .. I cannot understand.

Or the figure, or the person.

Headache.

But I saw a few words:

One of the principles of OO is that it is better to use an object combination than to use inheritance.

In addition:

When explaining the bridge mode, gof points out that the bridge mode "separates the abstract part from its implementation part.
Independent, so that they can change independently ". The "Implementation" here refers to how to implement it.
User requirements are implemented by means of combination (Delegation). Therefore, the implementation here does not refer to the inheritance basis.
Class, the implementation of the basic class interface, but refers to the realization of the user's needs through the combination of objects. I understand this point.
Bridge Mode, understanding the bridge mode, your design will be more elegant.

Is the abstraction here an abstraction that corresponds to user needs?

What is a bridge.

There are rivers under the bridge, and hills on both sides of the bridge. These people can access the bridge. The people here are not the average ones. The side of the bridge can be changed, but the side can remain unchanged.

A bridge is a link. The relationship is abstract. You can say that you are connected with zstack and stone ,... You can establish relationships for them.

Generally, in programming, one Party includes the other.

Let's talk about the surface form of the bridge.

Two abstract classes A1 and A2, where A1 can access A2 (A1 has a member pointing to A2 pointer. The reason why the pointer is used is fixed at runtime ). A1 and A2 can all be derived from many subclasses.

You only need to input an A2 class pointer in the A1 constructor, so that your A1 Class Object can access the corresponding A2 class members.

That's the case when we say so much.

Modifies the behavior of class objects by combining them. When a class object contains other class objects, you can change its behavior by changing the class objects it contains.

But don't forget to make them look nice, so that they have common or similar interfaces (member methods ).

I (/FN /)

////

A1 (// A2 * pq2 //) ------------ bridge --------------------------> A2

| //

A11 A12 A21 A22 A23

//

A1 * pa1 = new A11 (New A21 );

Pa1-> FN ();

Pa1 = new A12 (New A21 );

Pa1-> FN ();

Pa1 = new A11 (New A22 );

Pa1-> FN ();

// Note that the bridge mode is intended for user needs (I do not know what it means)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.