常见的 GUI 框架展示了哪些软件设计模式?

发布于 2025-01-08 08:02:17 字数 841 浏览 2 评论 0原文

我已经成为一名 Python 程序员 7 年多了,并且使用 PyQt 进行设计已经 3 年多了……但我不是受过经典训练的计算机科学家。主要的。最近,我一直在学习 Go 并积极关注 Golang-nuts 讨论列表,其中充满了非常聪明的开发人员。从这个讨论组中,我看到了很多关于软件设计模式的参考,例如Observer、Reactor等。同样,因为我不是CS专业的,所以我从未真正学习过所有这些术语和理论,但这让我想知道..

Qt、wx、GTK 等常见 GUI 框架表现出哪些设计模式?

我感觉它是不同组件的模式的混合体,例如事件循环与信号/槽或绑定与键-价值观察等等。我很想听到关于这些软件模式如何映射到这些框架的传统组件的解释或概括。

作为这个问题的一个次要因素:是否有 GUI 框架尝试采用完全不同的模式方法来实现 GUI 解决方案? Cocoa/objective-c 是否使用与其他事件循环模式相同的事件循环模式?

更新
为了帮助缩小问题的焦点,并根据 @HDDimon 的回答,我主要想知道行为模式(通信):
http://en.wikipedia.org/wiki/Design_Patterns#Behavioral_patterns

I have been a python programmer 7+ years now, and been designing with PyQt for 3+ years... But I am not a classically trained Comp Sci. major. More recently I have been learning Go and been actively following the Golang-nuts discussion list which is filled with extremely intelligent developers. From this discussion group, I have seen many references to software design patterns, such as Observer, Reactor, etc. Again because I am not a CS major, I never really learned all of this terminology and theory, but it made me wonder...

What design patterns do common GUI frameworks like Qt, wx, GTK exhibit?

I have a feeling like its a mixture of patterns for different components, such as the event loop vs signal/slots or binding vs Key-value observing, and so on. I would love to hear an explanation or generalization about how these software patterns map to the traditional components of these frameworks.

As a bit of a secondary element to this question: Are there GUI frameworks that try and take a completely different pattern approach to a GUI solution? Does Cocoa/objective-c use the same event loop patterns as these others?

Update
To help narrow down the focus of my question, and based on the answer by @HDDimon, I am mainly wondering about Behavior Patterns (communication):
http://en.wikipedia.org/wiki/Design_Patterns#Behavioral_patterns

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

£噩梦荏苒 2025-01-15 08:02:17

再会。我认为您可以在 Martin Fowler 文章 GUI 架构 中找到最佳答案。

来自这篇文章:

模型视图控制器 UI 开发中引用最广泛的模式可能是模型视图控制器 (MVC) - 它也是最常用的模式
错误引用。我已经记不清有多少次看到这样的描述了
事实证明 MVC 完全不是这样的。坦白说很多
原因是经典 MVC 的某些部分并没有真正的意义
如今对于富有的客户来说。但现在我们来看看
它的起源。

MVC 的核心,以及对后来的框架最具影响力的想法,就是我所说的分离呈现。这
分离演示背后的想法是进行明确的划分
在模拟我们对现实世界的感知的领域对象之间,
和表示对象,即我们在
屏幕。领域对象应该完全独立并且可以工作
在不参考演示文稿的情况下,他们也应该能够
支持多个演示,可能同时支持。这种做法
也是 Unix 文化的重要组成部分,并延续至今
允许通过图形界面操作许多应用程序
和命令行界面。


根据本文,用于划分任何类型组件的最佳模式类型是结构模式。

摘自“设计模式:可重用面向对象软件的元素”,作者:“四人帮” :埃里希·伽玛、理查德·赫尔姆、拉尔夫·约翰逊、约翰·弗利塞德斯。 (我真的很想推荐您阅读这本很棒的书)

  • 结构模式:
    • 适配器
    • 复合
    • 装饰器
    • 外观
    • 蝇量级
    • 代理

但是在任何类型的框架中,您都可以看到多种类型模式的混合:创建模式、结构模式、行为模式。

我从设计模式书中找到了模式之间的关系图,它可能对日常使用有帮助。

UPD:很好,已添加答案

Good day. I think the best answer you will find in Martin Fowler article GUI Architectures.

from this article:

Model View Controller Probably the widest quoted pattern in UI development is Model View Controller (MVC) - it's also the most
misquoted. I've lost count of the times I've seen something described
as MVC which turned out to be nothing like it. Frankly a lot of the
reason for this is that parts of classic MVC don't really make sense
for rich clients these days. But for the moment we'll take a look at
its origins.

At the heart of MVC, and the idea that was the most influential to later frameworks, is what I call Separated Presentation. The
idea behind Separated Presentation is to make a clear division
between domain objects that model our perception of the real world,
and presentation objects that are the GUI elements we see on the
screen
. Domain objects should be completely self contained and work
without reference to the presentation, they should also be able to
support multiple presentations, possibly simultaneously. This approach
was also an important part of the Unix culture, and continues today
allowing many applications to be manipulated through both a graphical
and command-line interface.

According to this article, the best types of patterns for division between any kinds of components is Structural Patterns.

from "Design Patterns: Elements of Reusable Object-Oriented Software" by The "Gang of Four": Erich Gamma, Richard Helm, Ralph Johnson, John Vlissides. (I really want recommend you to read this awesome book)

  • Structure Patterns:
    • Adapter
    • Bridge
    • Composite
    • Decorator
    • Facade
    • Flyweight
    • Proxy

But in any kind of frameworks you can see mix from several types of patterns: Creational patterns, Structural patterns, Behavioral patterns.

I had found a relational diagram between patterns from Design Patterns book, it may be helpful for everyday using.

UPD: Great SO answer added.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文