用于定义机器系统功能的设计策略建议

发布于 2024-08-17 16:19:43 字数 469 浏览 6 评论 0原文

这个问题涉及到项目设计。该项目采用一个电气系统并以编程方式定义其功能。现在我已经深入定义系统了,我正在整合大量的交互,这使得系统能够适当地配置自身。示例:当发生某些事件时,系统打开和关闭电气接触器。由于该系统位于飞机上,因此它依赖于空中/地面逻辑,因此根据其所在位置结合了两种不同的行为。

我给出所有这些解释是为了证明该应用程序所包含的复杂程度。在我的设计中,我使用了 if/else 结构作为推断该电气系统中正确配置的方法。然而,我越深入编码,就越需要更多的 if/else 结构。我觉得我已经到了对这个系统编程效率低下的地步。

对于那些以前处理过此类项目的人,我会问:我是否正在走一条众所周知的道路(当涉及到定义可能发生的每种可能情况时),我应该继续坚持下去......或者我可以采用一些其他策略来完成定义现实世界系统行为的任务。

在这一点上,我几乎没有使用委托的经验,但我想知道我是否可以利用一些观察者或其他“可可”的优点来检查场景,而不是无休止的 if/else 块。

This question relates to project design. The project takes an electrical system and defines it function programatically. Now that I'm knee-deep in defining the system, I'm incorporating a significant amount of interaction which causes the system to configure itself appropriately. Example: the system opens and closes electrical contactors when certain events occur. Because this system is on an airplane, it relies on air/ground logic and thus incorporates two different behaviors depending on where it is.

I give all of this explanation to demonstrate the level of complexity that this application contains. As I have continued in my design, I have employed the use of if/else constructs as a means of extrapolating the proper configurations in this electrical system. However, the deeper I get into the coding, the more if/else constructs are required. I feel that I have reached a point where I am inefficiently programing this system.

For those who tackled projects like this before, I ask: Am I treading a well-known path (when it comes to defining EVERY possible scenario that could occur) and I should continue to persevere... or can I employ some other strategies to accomplish the task of defining a real-world system's behavior.

At this point, I have little to no experience using delegates, but I wonder if I could utilize some observers or other "cocoa-ey" goodness for checking scenarios in lieu of endless if/else blocks.

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

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

发布评论

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

评论(2

舞袖。长 2024-08-24 16:19:43

由于您正在尝试对现实世界系统进行建模,因此我建议创建一个具体的面向对象设计,该设计很好地定义了 is-a 和 a has-a 关系,并应用良好的老式面向对象设计并将其应用于打破现实世界系统转化为功能分解。

我建议您研究定义处理一般情况的协议,并在特定情况下使用它们。

例如,您可以有许多类型的事件遵循 ElectricalEvent 协议,并且根据类型,您可以更好地决定 ElectricalContactor 如何使用 isKindOfClass 选择器区分 GeneralElectricEvent 和 SpecializedElectricEvent。

Since you are trying to model a real world system, I would suggest creating a concrete object oriented design that well defines the is-a and a has-a relationships and apply good old fashioned object oriented design and apply it into breaking the real world system into a functional decomposition.

I would suggest you look into defining protocols that handle the generic case, and using them on specific cases.

For example, you can have many types of events adhering to an ElectricalEvent protocol and depending on the type you can better decide how an ElectricalContactor discriminates on a GeneralElectricEvent versus a SpecializedElectricEvent using the isKindOfClass selector.

轻许诺言 2024-08-24 16:19:43

如果您可以提前定义所有状态,那么最好将其实现为 有限状态机。这使您可以在一个中心位置清楚地定义依赖于状态的逻辑。

您可以研究一些实现:

  • 生成状态机代码
  • SCM 允许您为 Objective-C OFC 将它们实现为 DFSM

当然,您也可以推出自己的自定义实现,如果这样的话更适合你。

If you can define all the states in advance, you're best of implementing this as a finite state machine. This allows you to define the state-dependent logic clearly in one central place.

There are some implementations that you could look into:

  • SCM allows you to generate state machine code for Objective-C
  • OFC implements them as DFSM

Of course you can also roll your own customized implementation if that suits you better.

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