AOP, signal/slot, and decoupling

Source: Internet
Author: User

Decoupling is an eternal topic. I didn't plan to start to involve "large-scale program decoupling" so early, but smithfox mentioned related topics on the winxcn forum, so I decided to talk about my views on "decoupling" here.

The essence of the idea of Aspect-oriented programming (AOP, Aspect Oriented Programming) is to encourage people to slice functions as much as possible to form independent services. Then, these services are assembled into required components by means of combination. AOP focuses onDecoupling of complex objects (or systems).

The signal-slot mechanism aims to provide a unified and scalable way to regulate the communication mechanism between components. Signal-slot focuses onDecoupling between components. Delphi, C #, QT, and smartwin (boost) all provide the signal-slot mechanism. In addition, the com connectpoint specification also belongs to the signal-slot category.

In smartwin, messages (or "events") are classified as aspect and provided in Singal-Slot Mode. What do you think? Why is the message mechanism of winx not similar to the signal-Slot Mechanism of smartwin? You can answer this question from the following four perspectives.

1. Compatibility. As I have already said, a tone of winx is to make existing MFC users feel familiar and happy. Therefore, I cannot use signal-slot, which is a stranger to MFC users, for message processing.

Second, efficiency. The smartwin message mechanism makes the size of window objects expand rapidly, and the efficiency of message distribution is greatly reduced.

Third: the main focus of signal-slot isDecoupling). Generally, it is used for message communication between two objects (or multiple objects. Delphi, C #, and Qt have a good grasp of this point. However, smartwin applies the signal-Slot Mechanism to message dispatching in the window itself, which makes people feel a little like a cool.

Aspect 4: From the AOP perspective. The focus of AOP is to provide services (function slicing). smartwin only classifies messages as aspect and does not provide services. It seems that this aspect is mainly for implementation reuse, and I personally think it is of little significance. The true consistency of AOP thinking is ATL/wtl (of course, since smartwin supports signal-Slot of all messages, it can also implement "function slicing" one by one, even though I haven't seen it yet, but this may be because I am not familiar with smartwin ). The messagemap chain mechanism in message dispatching of ATL/wtl enables Message ProcessingSplit by function sliceAnd finally can be perfectly assembled together. In ATL/wtl, there are too many "function slices" (a bit of bragging, but not much :--). We can give a few examples at will:
-Wtl: cdialogresize (window layout, not only used for layout of DIALOG)
-Wtl: cdoublebufferimpl (dual buffer paint mechanism supported)
-Wtl: cthemeimpl (XP theme supported)
-...

Next, let's talk about winx.Decoupling). I once mentioned this problem in the confusing article of C ++ programmers (but this problem is not unique to C ++ programmers) and regard it as a goal to be solved by winx. I have tried this and achieved some results. But I'm sorry, there is still a gap between it and my expectation. The code for this part is not open yet.

Finally, I want to compare the various signal-slot implementations.

Delphi and C # support the signal-slot mechanism from the syntax point of view. The performance, convenience and friendliness are obviously the best (Delphi only supports one slot for efficiency ). Although QT is based on C ++, its signal-slot mechanism is also provided from the "semi-syntax perspective" (so with MOC preprocessing ).

According to my guess, the author of smartwin thought that QT's practice was not pure and tried to provide a standard C ++ solution. However, there are two reasons why I think the smartwin (or boost) signal-slot mechanism is poor:

1. Singal-slot is a general decoupling mechanism. It applies components at various levels, not just for window message processing. Therefore, the singal-slot mechanism is simple and easy to use. This made me inclined to implement the singal-Slot of QT (only compared to smartwin and boost ).

Second: Since signal-slot is concerned with decoupling between components, I personally prefer it to be a binary specification, rather than a specification defined by the C ++ template. The reason is simple: I don't want to assume that all the component implementers like C ++.

What is the biggest difference between the. NET platform and the Java platform? Separate your focus from the comparison between C # and Java. In fact, the biggest difference between the two is that the. NET platform is pushing its binary specification CLR (extended from the com binary specification), while the Java platform is pushing the Java language. Microsoft is smart. Er, I have moved the topic far away.

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.