如何以模块化的方式设计应用程序?

发布于 2024-08-14 07:24:12 字数 708 浏览 8 评论 0原文

我正在寻找有关“如何以模块化方式设计应用程序”的指示、建议、链接、警告、想法甚至轶事。我将在这个项目中使用 python,但建议不一定要参考这种语言,尽管我只愿意实现基于 OOP 的设计。

这里有一些上下文可以帮助您了解我来自哪里以及做什么我正在尝试实现...


我的项目将是一个小型应用程序,它将使用 Web 服务并以多种方式显示结果,包括:

  • 调用选项卡的结果
  • 通知弹出窗口仅包含应用程序主窗口中的 从检索到的消息原始数据
  • 缓冲区绘制的图形(按需可见),其中来自各种服务的结果将堆积

该应用程序将作为免费(如语音)软件发布,因此我想使其他开发人员可以轻松编写插件/模块,从而扩展主应用程序的功能,而无需更改核心代码。

此时,插件本质上应该使开发人员能够通过定义提供者、数据操作(如果有)以及向用户呈现数据的方式来激活新的 Web 服务

我在使用 drupal 进行开发方面拥有丰富的经验,它具有强大的模块化方法,但也遵循非面向对象的设计,所以我怀疑对于python来说,drupal设计可能不是最优的解决方案。

如果这很重要的话——核心将为 GNU/Linux 原生开发。

预先感谢您的宝贵时间!

I am looking for pointers, suggestions, links, warnings, ideas and even anecdotical accounts about "how to design an application in a modular way". I am going to use python for this project, but advice does not need to necessarily refer to this language, although I am only willing to implement a design based on OOP.

Here's some context to understand where I come from and what I am trying to achieve...


My project will be a small application that will consume web services and display the results in a variety of ways, including:

  • notification popup containing just the result of the call
  • tab in the main window of the application with graphics plotted from retrieved raw-data
  • buffer of messages (visible on domand) where results from various services will pile up

The application will be released as free (as-in-speech) software, and for this reason I would like to make it really easy for other devs to write plugins/modules that will extend the functionality of the main application without needing to change the core code.

At this point in time, plugins should essentially enable a developer to activate a new webservice, by defining the provider, the data manipulation (if any) and the way the data will be presented to the user.

I have extensive experience in developing with drupal which has a powerful modular approach, but that also follows a non-object-oriented design, so I suspect that for python, drupal design might not be the optimal solution.

If this is of any importance - the core will be natively developed for GNU/Linux.

Thank you in advance for your time!

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

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

发布评论

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

评论(5

一个人练习一个人 2024-08-21 07:24:12

尝试保持事物松散耦合,并大量使用接口来提供帮助。

我会从关注点分离开始设计。主要的架构层是:

  • 问题域(又名引擎、后端):域类,完成所有实际工作,具有域知识实现域行为
  • 持久性:域类的存储管理,数据库/文件系统层
  • 用户界面: GUI,与域类
  • 系统接口对话:与其他系统对话,例如。网络、Web 服务

域类完成工作,但不了解 UI。持久层了解域类,足以根据需要保存/加载。系统接口层抽象了外部系统,使您可以在测试时在后面插入模拟器。理想情况下,UI 应使用 MVC,以获得最大的灵活性。

不说太多,人们通常不会将 Drupal 视为优秀架构设计的典范。它已经相当有机地发展,并且设计发生了许多变化,系统升级时经常出现的插件损坏就证明了这一点。

我也会回应 MicSim 所说的,关于仔细设计插件界面并编写多个不同的插件来练习它。这是真正充实应用程序和插件如何交互的问题的唯一方法。

Try to keep things loosely coupled, and use interfaces liberally to help.

I'd start the design with the Separation of Concerns. The major architectural layers are:

  • Problem Domain (aka. Engine, Back-end): the domain classes, which do all the actual work, have domain knowledge implement domain behaviour
  • Persistence: storage management for domain classes, database/filesystem layer
  • User Interface: the GUI, which talks to the domain classes
  • System Interfaces: talking to other systems, eg. networking, web services

The domain classes do the work, but don't know about the UI. The persistence layer knows about the domain classes, enough to save/load as required. The system interface layer abstracts away external systems, which lets you plug a simulator in behind while testing. The UI should ideally use MVC, for maximum flexibility.

Without putting too fine a point on it, one would not ordinarily look to Drupal as an exemplar of good architectural design. It has grown rather organically, and there have been many upheavals of the design, as evidenced by the regular plugin breakage upon system upgrades.

I would also echo what MicSim said, regarding carefully designing the plugin interface and writing multiple different plugins to exercise it. This is the only way to really flesh out the issues of how the app and plugins interact.

过期情话 2024-08-21 07:24:12

由于您将通过应用程序提供一些基本功能,因此请确保您自己将可扩展/可替换的部分编码为插件。然后您将最好地了解您的 API 应该是什么样子。

为了证明 API 是好的,你应该编写第二个和第三个插件,因为那时你会发现你在编写第一个插件时做了很多假设。通常,在完成第二步和第三步之后,事情会变得更加清晰。

现在,您应该再编写一个插件,因为您编写的最后一个插件在类型、输入数据和表示方面类似于第一个插件(可能是另一个天气 Web 服务)。选择完全不同的东西,使用完全不同的数据,你会发现你的 API 仍然过于定制。 (否则你做得很好!)

As you will deliver some basic functionality with your app, make sure that you code the part that should be extendable/replaceable already as a plugin by yourself. Then you'll best get a feeling about how your API should look like.

And to prove that the API is good, you should write a second and third plugin, because then you will discover that you made a lot of assumptions when writing the first one. Normally things clear up a bit after doing this 2nd and 3rd step.

Now, you should write one more plugin, because the last plugins you wrote resemble the first one in type, input data and presentation (maybe yet another weather webservice). Choose something total different, with absolutely different data, and you will see your API being still too tailored. (Else you did a good job!)

为你拒绝所有暧昧 2024-08-21 07:24:12

好吧,可能首先要坐下来弄清楚插件可能需要什么来实现其目的。

您需要在设计中考虑两个主要方面。

  • 您的框架将如何传递请求/接收来自插件的响应?
  • 提供哪些辅助类或模块可能会更好?

也许也是,因为这听起来像是一个学习项目。

  • 您想自己写什么,以及您乐意从现有的库中挑选什么?

我还建议您在设计 API 时开发一些基本插件。必须实际使用您的设计的经验将使您能够看到给定的方法可能会使事情变得比实际需要的更困难。

Well, probably the first place to start is to sit down and figure out what the plug-in might need to fulfill its purpose.

You'd want to consider two main aspects in your design.

  • How will your framework pass requests / receive responses from the plug-in?
  • What helper classes or modules might be good to provide?

And probably also, since this sounds like a learning project.

  • What do you want to write yourself, and what are you happy just to pick out of an existing library?

I'd also recommend developing some basic plugins as you design the API. The experience of having to actually use what you design will allow you to see where a given approach might be making things harder than they need to be.

梦境 2024-08-21 07:24:12
  • 仔细为您的应用设计 API(如何设计良好的 API 及其重要性
  • 将所有可以独立使用的东西都做成一个模块,然后从简单的部分中分组并构建更大的部分(KISS)
  • 不要重复自己(DRY)
  • 经常为自己和他人编写/发布简短的文档(开源口头禅) ...
  • design the api for your app, carefully (How To Design A Good API and Why it Matters)
  • make everything, which could be used independently a module, then group and build larger parts out of the simple parts (KISS)
  • don't repeat yourself (DRY)
  • write/publish short documentation frequently, for yourself and others (open source mantra) ...
゛清羽墨安 2024-08-21 07:24:12

查看侦听者-订阅者模式。迟早,您的应用程序将变得足够复杂,您需要实现回调。当您达到该限制时,请使用侦听器订阅者(wxPython 中有一个实现)。

例如,多个模块想要从多个提要中监视新数据。链接在一起的模块可能希望根据新数据进行自我更新。

Look into the listener-subscriber pattern. Sooner or later, your app will be complex enough that you need to implement callbacks. When you hit that limit, use listener-subscriber (there's an implementation in wxPython).

For example, several modules will want to watch for new data from a number of feeds. Modules that link together might want to update themselves, based on new data.

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