C # design Pattern bridge design mode (bridges)

Source: Internet
Author: User
Tags abstract definition inheritance

Bridges (bridge) mode

Bridge mode is a very useful model, but also a more complex one. Familiarity with this pattern is helpful in understanding object-oriented design principles, including the "open-close" principle (OCP) and the combination/aggregation reuse principle (CARP). Understanding these two principles will help to form the correct design ideas and develop a good design style.

Note: "Java and Mode" a book that bridge mode is not a very high frequency of use of the model, I do not agree, I think the bridge model contains a lot of design patterns of the key ideas in the inside, so I adopted the "Designing Patterns Explained" The author of the book, Alan Shalloway, and James R. Trott's view: The bridge is quite a bit more complex than the other patterns you just Lear Ned It is also much more useful.

The purpose of bridge mode

"GOF95" in the proposed bridge model when pointed out that the bridge model is intended to "abstract (abstraction) and implementation (implementation) decoupling, so that the two can independently change." This sentence has three key words, namely abstraction, realization and decoupling.

Abstraction of

The common conceptual connection that exists in multiple entities is abstraction. As a process, abstraction is the omission of some information, which treats the "LISKOV94" as a different entity.

Implementation of

The concrete realization of abstraction is realization.

Decoupling

The so-called coupling is a strong association of the behavior of two entities. And their strong association is removed, is the coupling of liberation, or decoupling. Decoupling, in this case, is to free the coupling between abstraction and implementation, or to change the strong association between them to a weak association.

Changing the inheritance relationship between two roles to an aggregation relationship is to change the strong association between them to a weak association. Therefore, the so-called decoupling in the bridge mode means that the combination/aggregation relationship is used between the abstraction and the implementation of a software system rather than the inheritance relationship, so that the two can change relatively independently. This is the purpose of the bridge model.

II. structure of the bridge model

The bridge mode "GOF95" is the object's structure pattern, also known as the handle body (Handle) mode or interface (Interface) mode.

The diagram below shows a structural diagram of a schematic system that implements a bridge pattern.

As you can see, this system contains two hierarchical structures, namely:

An abstract hierarchical structure composed of abstract roles and modified abstractions.

A hierarchical structure of implementations composed of the implementation role and two concrete implementation roles.

The roles involved in the bridge model are:

Abstract (abstraction) role: Abstract the definition given, and save a reference to the materialized object.

Fixed abstract (refined abstraction) role: Extends the abstraction role, changes and corrects the definition of the abstract of the parent class.

Materialized (implementor) Role: This role gives the interface for implementing the role, but does not give a specific implementation. It must be pointed out that this interface is not necessarily the same as the interface definition of the abstract role, in fact, the two interfaces can be very different. The implementation role should give only the underlying operations, and the abstract role should only give a higher level of operation based on the underlying operation.

Concrete implementation (concrete implementor) Role: This role gives the realization of the implementation of the role interface.

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.