代码组织:如何最好地对函数、类等进行分组
场景:您有一个规模合理的项目,其中包含一些表单、类等。
问题:您将如何对您的功能进行分组?您会将所有形式共有的功能放入一个单独的类中,还是根据功能将多个类放入其中?你的数据库调用怎么样?您是否有一个包含所有数据库函数的类?或者您会创建一个可以处理调用的实用程序类吗?
原因:我正在寻找有关如何最好地“分组”功能的指导。例如,我可以看到,将所有数据库函数放在一个类中将使以后更容易更改/调试,但有必要吗?我偏爱为您处理所有连接并返回格式化结果的实用程序,但 SQL 代码最终确实到处都是。
尾注:我知道有很多问题,但正如我所说,我正在寻找方向,你不必接受每个答案并回答 T,但需要一些编码指南或一些来自过去经验的编码智慧将不胜感激 非常
感谢,
Scenario: You have a reasonably sized project with some forms, classes, etc.
Question: How would you group your functions? Would you put the functions common to all the forms into one separate class or a number of classes depending on function? What about your database calls. Would you have one class that contained all your database functions? Or would your create a utility class that would handle the calls?
Reason: I'm looking for some direction on how to best "group" functions. For instance I can see that having all the database functions in one class would make it easier to change/debug later, but is that necessary? I'm partial to the utility that handles all the connections for you and returns the formatted result but the SQL code does end up all over the place.
End Note: I know there are a lot of questions but as I said I'm looking for direction, you don't have to take every answer and answer it to a T but some coding guidelines or some coding wisdom from past experiences would be greatly appreciated
Many thanks,
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
查看3 层架构。但如果您正在寻找更深入的内容,有很多关于应用程序架构主题的好书。您可以尝试企业应用程序架构模式。
Check out 3-Tier Architecture. But if you're looking for something more in depth, there are many great books on the subject of Application Architecture. You could try Patterns of Enterprise Application Architecture.