The bridging mode of the. NET design pattern instance (bridge pattern)

Source: Internet
Author: User
Tags inheritance

Introduction of Bridging Mode (Brief Introduction)

Bridging pattern, which separates the abstract part from its implementation, enables the abstraction and implementation to change independently.

Decouple an abstraction to implementation so this two can vary independently.

What is aggregation/combination:

Aggregation (Aggregation), when object A is added to object B and becomes part of Object B, an aggregation relationship between object B and object A. Aggregation is a kind of association relation, it is a strong relation, which emphasizes the relationship between the whole and the part.

Scene: the product and his specifications, style is the aggregation relationship.

Aggregation diagram of classes and classes

Combination (composite), object A contains object B, and object B leaves object a without practical meaning. is a stronger association relationship. A man contains his hand, and his hand leaves his body to lose its proper function.

Scene: The window form is a combination of slider slider, header header, and Workspace panel.

Combination of class and class diagram

Aggregation and synthesis principles: use aggregations or combinations as much as possible, and try not to use class inheritance.

An object's inheritance relationship is defined at compile time, so the implementation inherited from the parent class cannot be changed at run time. The implementation of a subclass has a very close dependency on its parent class, so that any change in the implementation of the parent class will inevitably result in a subclass change. When a subclass is needed, the parent class must be overridden or replaced by a more appropriate class if the integrated implementation does not meet the new problem. This dependency limits flexibility and ultimately limits reusability.

Ii. issues addressed (What to Solve)

When the system has multidimensional angle classification, and each classification is likely to change, then consider the use of bridging mode is more appropriate.

Bridging mode Analysis 1, bridging mode structure

Related Article

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.