如何着手设计一个模块?

发布于 2024-12-10 20:55:35 字数 272 浏览 0 评论 0原文

当你需要设计一个模块时,你通常会怎么做?到目前为止,我已经关注了它的易用性、API 的直观性、可扩展性、性能以及诸如此类的问题。

但对我来说看似相当简单和直接的事情对于其他用户来说可能显得过于复杂。虽然这种情况并不经常发生,但有时确实会发生在我们所有人身上(我希望)。

除了我已经提到的问题之外,在设计类层次结构/API/其他内容之前,在继续编码之前,您还应该问自己什么问题吗?

如果您认为该问题更适合 SO 的其他部分,请随意迁移它,但我仍然想要一个答案。

干杯。

How do you usually go about when you need to design a module? Till now I've taken care of how easy it is to use, how intuitive its API is, extendibility, performance and stuff like that.

But what seems fairly simple and straight-forward to me might seem over-complicated for other users. Although it doesn't happen that often, it does happen sometimes to all of us (I hope).

Are there any questions that you should ask yourself before designing a class hierarchy/API/whatever before you proceed with coding, other than the issues I already mentioned?

If you believe the question is better suited for a different section on SO please feel free to migrate it, but I'd still like an answer.

Cheers.

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

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

发布评论

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

评论(2

旧街凉风 2024-12-17 20:55:35

你的问题是一个很好的问题,并且有答案,但太复杂,答案基本上是编程经验。

制作软件有一些通用原则,但我认为在这里,在这个简短的回答中,我可以给您一个可以应用的概念。软件是一个领域的表示(例如银行软件是为了定制金融系统而制作的,或者雷达软件是为了定制雷达检测的思想和原理而制作的)。因此,软件就像一种理论:它完美地适合您所在领域的当前知识,允许推理和扩展。如果有更多的知识可用,则应该对理论进行扩展、完善或使其更加普遍,以适应新的知识,同时仍然对先前的知识保持有效。

因此,所有关于理论的概念都适用:

  • 在一个听起来同质且集成良好的统一框架中满足您的知识所施加的要求。
  • 简单,但寻找可以变得更通用的模式,并重点关注这些模式以实现更好的集成。
  • 别太简单了。如果你的软件不符合要求,那么你的理论就太有限了,必须进行扩展。
  • 让你的软件适应新的需求,软件并不是一成不变的。它会变异和发展,以适应新的需求,或失去不再需要的功能。

所以,软件应该简约但不要太多,美观但实用。

在将这些方向付诸实践时,我建议您留出时间来学习您的领域。你无法对你不理解的东西进行建模。学习基础知识,从简单的事情开始,然后逐步完善它们。你偶尔会发现有些东西“感觉”在错误的地方。问自己一些问题,例如

  • “谁负责执行此操作?”
  • “这种依赖关系是否符合逻辑并且是该对象正常工作所必需的,或者它只是由于糟糕的代码组织而产生的虚假依赖关系?”
  • “这是高级功能还是低级功能?”
  • “我是在重复这句话吗?”
  • “我可以在外部代码不知道的情况下在内部更改此对象/层/子系统吗?”
  • “我可以在未来扩展这个而不破坏或使过去无效吗?”
  • “我可以轻松测试和探测此功能以获得正确的行为吗?”
  • “理解和使用起来是否简单直观?”
  • “我可以轻松地重新组合我已经拥有的东西,而不需要碰触来实现新的行为吗?”
  • “这个功能是否被隔离,以便我可以向外界展示它,而无需我操作大量其余代码?”

Your question is a very good one, and one that has answers, but so complicated that the answer is basically the experience in programming.

There are general principles to make software, but I think that here, in this short answer, I can give you one concept that you can apply. Software is a representation of a domain (such as a bank software is made to tailor the financial system, or a radar software is made to tailor the ideas and principles of radar detection). Software, therefore, is like a theory: it fits the current knowledge of your domain perfectly, allows inferences and extensions. If more knowledge becomes available, the theory should be extended, polished or made more general to accommodate this new knowledge, while still remaining valid for the previous knowledge.

Hence, all the concepts about theories apply:

  • satisfy the requirements imposed by your knowledge in a unified framework that sounds homogeneous and well integrated.
  • be simple, but look for patterns that you may make more general, and spotlight these patterns for better integration.
  • don't be too simple. If your software does not fit the requirements, your theory is too limited and must be extended.
  • allow your software to accommodate new requirements, software is not cast in stone. it mutates and evolves, accommodating the new requirements, or losing functionalities that are no longer needed.

So, software should be minimalistic but not too much, beautiful but practical.

When it comes to put into practice these directions, I suggest you to allow time for learning your domain. You can't model something that you don't understand. Learn the basics, and start from something simple, then progressively refine them. You will occasionally see that some things "feel" in the wrong place. Ask yourself questions such as

  • "who is responsible to do this operation?"
  • "Is this dependency logical and needed for this object to work, or is it just a spurious one due to bad code organization?"
  • "Is this high-level or low-level functionality?"
  • "Am I repeating this ?"
  • "can I change this object/layer/subsystem internally without the code outside knowing ?"
  • "can I extend this in the future without ruining or invalidating the past ?"
  • "can I test and probe this functionality easily for correct behavior ?"
  • "Is it easy and intuitive to understand and use ?"
  • "can I recombine what I already have easily and without touching to implement new behavior?"
  • "Is this functionality isolated so that I can show it to the outside world without the bulk of the rest of the code I manipulate ?"
奢华的一滴泪 2024-12-17 20:55:35

您应该考虑SOLID原则此处

关于责任分配,适用GRASP 模式

You should consider SOLID Principles and here.

And about responsibility assigment apply GRASP Patterns

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