代表硬件设备的适当类结构

发布于 2024-12-17 06:06:18 字数 543 浏览 0 评论 0原文

我正在尝试编写基本心电图设备的接口。我需要表单来设置设备、发送“记录”消息并将返回的心电图数据保存到文件中(以及在屏幕上报告一些信息)。硬件设备接收发送的命令,并通过串行接口返回数据。

我的问题是关于建立最合适的班级结构。

选项 1: MainWindow实例化一个 硬件设备对象实时读取心电图信息,创建“心电图文件类对象”并在设备对象内部处理所有内容。 录制完成后,MainWindow 删除设备对象,我们就完成了。

选项2: MainWindow 实例化 接收大量数据的硬件设备对象,将该数据维护为可公开访问的数据结构(成员),然后 然后,MainWindow 将引用该设备对象数据结构,实例化 ECG 文件类对象本身并将其写入文件。

理想情况下,我想以不同的格式写出数据(例如指定格式的类?)

抱歉,如果问题不太清楚,我想我是在问硬件设备对象是否也适合管理其所有自己的数据,或将其传回主窗口,然后自行处理。

我尝试过选项 1,但它变得越来越难看,而且我不确定我是否从一开始就设计错误了。

任何/所有意见表示赞赏!

皮特

I'm trying to code up an interface to a basic ECG device. I need the form to setup the device, send the 'record' message and save the ECG data that comes back into a file (as well as report a bit on the screen). The hardware device gets sent commands, and returns data via a serial interface.

My question is about the most appropriate class structures to set up.

Option 1:
MainWindow instantiates a
Hardware Device Object that reads the ECG info realtime, creates an 'ECG File class object' and handles it all internally to the Device object.
When recording is finished, MainWindow deletes the Device object and we're done.

Option 2:
MainWindow instantiates the
Hardware Device Object that receives a whole lot of data, maintains that data as a publically accessible data structure (member) then
MainWindow would then refer to that Device Object data structure, instantiate the ECG File class object itself and write it out to a file.

Ideally I'd like to write the data out in different formats (eg. classes that specify the format?)

Sorry if the question's not that clear, I guess I'm asking whether it's appropriate for a hardware device object to also manage all its own data, or pass it back for the main window to then process itself.

I've had a go at option 1, but it's getting ugly and I'm not sure whether I've mis-designed the thing from the start.

Any/all views appreciated!

Pete

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

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

发布评论

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

评论(1

木落 2024-12-24 06:06:18

由于对域了解不多,我设计了几个使用设备的系统。我还看过一些设备设计。设计这类东西的方法有很多,但我喜欢为所有设备编写包装器并使用打开、关闭、读取和写入接口。

因此本质上,创建了一个名为 Device 的抽象类。可以设计特定的设备来扩展这个基类。然后创建一个构建器类来创建和初始化特定的类。从这个基本类可以构建一个系统来处理它的输入和输出。我倾向于设计接口并使类尽可能简单。

Not knowing too much about the Domain, I have designed several systems that uses devices. I have also seem some design for devices. There are many ways to design this kind of stuff, but i like to write wrappers for all devices and use an open, close, read, and write interface.

So essentially, an abstract class is created called Device. Specific devices can be designed to extend this base class. Then a builder class is created to create and initialize the specific class. From this basic class a system can be built to handle it's out input and output. I tend to design to interfaces and keep classes as simple as possible.

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