如何着手设计一个模块?
当你需要设计一个模块时,你通常会怎么做?到目前为止,我已经关注了它的易用性、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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
你的问题是一个很好的问题,并且有答案,但太复杂,答案基本上是编程经验。
制作软件有一些通用原则,但我认为在这里,在这个简短的回答中,我可以给您一个可以应用的概念。软件是一个领域的表示(例如银行软件是为了定制金融系统而制作的,或者雷达软件是为了定制雷达检测的思想和原理而制作的)。因此,软件就像一种理论:它完美地适合您所在领域的当前知识,允许推理和扩展。如果有更多的知识可用,则应该对理论进行扩展、完善或使其更加普遍,以适应新的知识,同时仍然对先前的知识保持有效。
因此,所有关于理论的概念都适用:
所以,软件应该简约但不要太多,美观但实用。
在将这些方向付诸实践时,我建议您留出时间来学习您的领域。你无法对你不理解的东西进行建模。学习基础知识,从简单的事情开始,然后逐步完善它们。你偶尔会发现有些东西“感觉”在错误的地方。问自己一些问题,例如
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:
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
您应该考虑SOLID原则和此处。
关于责任分配,适用GRASP 模式
You should consider SOLID Principles and here.
And about responsibility assigment apply GRASP Patterns