1

我想编写一个完全与视图无关的 C++ 应用程序框架。理想情况下,我希望能够使用以下任一作为“前端”

  1. Qt
  2. 网页前端

我知道 Web 工具包 (wt) 等开发,但我想避免这些开发,至少有以下原因之一:

  1. 他们使用 cgi/fastcgi 方法(使用 Apache 时)

  2. AFAIK,他们强加了一个“前端”框架给你——例如,我不能使用 CakePHP、Symfony、Django 等来创建网页,并且在页面绑定到服务器端 C++ 应用程序时只有“小部件”。我想自由地使用我想要的任何 Web 框架,这样我就可以从许多流行和成熟的模板框架(例如 Smarty 等)中受益。

我认为 MVC 模式的一些变体(不确定哪种变体)在这种情况下可以很好地工作。

这就是我打算继续的方式:

  • 模型和控制器层用 C++ 实现
  • 插件位于控制器和视图之间
  • 该视图是使用 QT 或第三方 Web 框架实现的
  • 视图(前端)和插件之间的通信使用以下任一方式完成:

    一世。QT 前端的事件

    ii. Web 前端的 AJAX/PUSH 机制(也许在这里可以使用backbone.js?)

我上面描述的模式是否有一个名称 - 以及(在我开始编码之前),我应该注意什么(如果有的话)有什么陷阱/性能问题(网络延迟除外)?

4

1 回答 1

1

从它的声音来看,它是一个 MVC,插件实现了控制器和视图之间的桥梁。我找不到一个 MVC 变体,它专门有一个桥作为设计的参与者;但是,它们都没有阻止桥接器或其他模式协作或实现 MVC。

实现这一点的困难可能来自桥接抽象。可能很难:

  • Prevent implementation details from affecting the abstraction. For example, if implementation A has an error code that is only meaningful to implementation A and implementation B has an error code that is similar but occurs under different conditions, then how will the errors pass through the abstraction without losing too much meaning?
  • Account for behavioral differences between implementations. This generally requires a solid understanding of the implementation being abstracted so that pre-conditions and post-conditions can be met for the abstraction. For example, if implementation A supports asynchronous reads, and implementation B only supports synchronous reads, then some work will need to be done in the abstraction layer to to account for the threading.
  • 在解耦和性能之间找到可接受的折衷方案。这将是一个平衡的行为。与往常一样,尽量避免过早的优化。通常,为了性能而引入一点耦合比解耦高性能代码更容易。

此外,考虑利用其他模式来帮助解耦。例如,如果具体类型Foo需要通过抽象层传递,实现A将其转换为Foo_A,而实现将其转换为Foo_B,则考虑让插件提供一个Abstract FactoryFoo将成为 and 的抽象基类Foo_AFoo_B并且插件将提供一个工厂来创建实现Foo的对象,从而允许控制器分配插件期望的确切类型。

于 2012-07-11T21:45:26.910 回答