Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What is the concept of bridging pattern in web design pattern

2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/01 Report--

Most people do not understand the knowledge points of this article "what is the concept of bridging pattern in web design pattern?", so the editor summarizes the following content, detailed content, clear steps, and has a certain reference value. I hope you can get something after reading this article. Let's take a look at this "what is the concept of bridging pattern in web design pattern" article.

motivation

When an abstraction may have multiple implementations, inheritance is usually used to coordinate them. Abstract classes define interfaces to that abstraction, while concrete subclasses are implemented in different ways. But this method is sometimes inflexible. The inheritance mechanism fixes the abstract part with its implementation part, which makes it difficult to modify, expand and reuse the abstract part and the implementation part independently.

Polymorphism is one of the basic object-oriented techniques, which is usually realized by inheritance when a feature of a class needs to change. Imagine that there is a communication port class CommPort, which can open the port, close the port, send and receive data and so on. If we need to support different modes of communication, we will derive a WifiPort class or BluetoothPort class, and if we need encryption or MD5 verification, we will derive Base64Port or Md5Port. Although this approach is easy to understand, there is a problem that it is not flexible enough. For example, when generating Md5Port to add parity information, it is often necessary to specify a transmission mode. At this point, the class will most likely become Md5WifiPort, and the encoding and communication methods need to be bound together. There is no way to combine freely. If you need new functionality, you need to build new classes.

Let's consider the implementation of a portable abstract part of Window in a user interface toolkit. For example, this abstract part should allow users to develop applications that can be used in both X Window System and IBM's Presentation Manager (PM) systems. Using inheritance mechanism, we can define Window abstract class and its two subclasses, XWindow and PMWindow, and use them to implement Window interface on different system platforms. However, the inheritance mechanism has two shortcomings:

1) it is inconvenient to extend Window abstraction to different kinds of windows or new system platforms. Suppose you have a subclass of Window, IconWindow, which specializes in Window abstraction for icon processing. In order for IconWindow to support two system platforms, we have to implement two new classes, XIconWindow and PMIconWindow, and to make matters worse, we have to define two classes for each type of window. In order to support the third system platform, we also have to define a new Window subclass for each window.

All operations on the Window subclass are implemented using abstract operations in the WindowImp interface. This separates the abstraction of the window from the implementation part related to the system platform. Therefore, we call the relationship between WindowWindowImp a bridge because it acts as a bridge between an abstract class and its implementation, allowing them to change independently.

The above is the content of this article on "what is the concept of bridging pattern in web design pattern". I believe we all have a certain understanding. I hope the content shared by the editor will be helpful to you. If you want to know more related knowledge, please pay attention to the industry information channel.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report