项目命名
作为一名初学者/中级开发人员,随着我的项目变得越来越大、越来越抽象,我遇到了一个问题,因为我使用了更多的 OOP 原则,我在命名事物时遇到了问题。 就像当我有多个项目或类库时,我不知道如何命名它们。 我看到了从 xxx.Core 到 xxx.Main 的内容,甚至还看到了 xxx.BLL 和 xxx.DAL。 在浏览其他人时,我看到了 xxx.Services 和 xxx.Data 的库和命名空间。
那么一旦这个问题解决了,我该如何调用DTO呢? 在那个领域我看到了 xxx.DTO、xxx.Entities、xxx.Props。
在编码时,有哪些好的命名库、方法、接口等的指南,以便越来越多的人在我之后接手这个项目时能够理解一些事情。
As a beginner/intermediate developer one problem I run into as my projects get bigger and more abstracted away as i use more OOP principles I have a problem with naming things. Like when i have multiple projects or class libraries I don't know what to name them. I see things from xxx.Core to xxx.Main or have even seen xxx.BLL and xxx.DAL. While looking through others i have seen xxx.Services and xxx.Data for their library and namespaces.
Then once that is solved is what do i cal DTO's? In that realm i have seen xxx.DTO, xxx.Entities, xxx.Props.
What are some good guidelines to naming libraries, methods, interfaces, etc... while coding so that more and more people will understand things when they come to pick up the project after me.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
同意汤姆·安德森的观点,即你不必害怕打字。 试图使所有内容尽可能短,这对命名法来说是一个比人们意识到的更大的障碍,而命名法对开发的障碍也比人们意识到的更多。
Agreed with Tom Anderson that you need to not be afraid of doing some typing. Trying to make everything as short as possible is more of a roadblock to nomenclature than people realize, and nomenclature is more of a roadblock to development than people realize.
嘿%20,很高兴在这里见到你:)(假设你是来自 3dbuzz 的人)
无论如何,使用命名空间和文件夹! 如果不需要,请不要疯狂使用 DLL。 对于我假设您正在谈论 DLL 的应用程序类型可能有些过分了。 在 C# 中使用文件夹和命名空间。 例如:
在 C++ 中,我通常:
在 PHP 中,没有命名空间会更困难。 但我仍然遵循与 C# 中相同的文件夹结构,但我命名我的类以弥补没有命名空间的情况。 例如,如果在 C# 中,我在 Application.Controllers.Course 命名空间下有一个名为“Index”的类,那么在 PHP 中,我会这样称呼它:
无论如何,如果没有必要,请不要对 DLL 疯狂。 我无法忍受看到包含超过 5 个 DLL 的应用程序,这些 DLL 除了在主 EXE 中之外从未在其他地方使用过。
Hey %20, fancy seeing you here :) (assuming you are the one from 3dbuzz)
Anyhow, use namespaces and folders! Don't go crazy with DLLs if you don't need to. For the kind of applications I am assuming you are talking about DLLs will probably be overkill. In C# use folders and namespaces. For example:
In C++, I usually:
In PHP it's harder without namspaces. But I still follow the same folder structure as in C# but I name my classes to make up for no namespaces. For example, if in C# I had a class called "Index" under the Application.Controllers.Course namespace, in PHP I would call it:
Anyway, please don't go DLL crazy without a good need for it. I cant stand seeing applications with over 5 DLLs that are never used elsewhere besides in the main EXE.
缩写通常不好。
数据访问层
YourCompany.Data.dll
实体层
YourCompany.Data.Entities.dll
业务层
YourCompany.BusinessLogic.Name.dll (例如:YourCompany.Accounting.Services.dll)
这也不是金子,我确信您还有很多其他类型的方法可以做到这一点,我们做到了这样可以更轻松地找到项目、程序集并构建正确的部署。 另外,在查看程序集时,看到全名而不是“MS.BLL.dll”要友好得多。
Abbreviations are in general bad.
Data Access Layer
YourCompany.Data.dll
Entity Layer
YourCompany.Data.Entities.dll
Business Layer
YourCompany.BusinessLogic.Name.dll (example: YourCompany.Accounting.Services.dll)
This isn't gold either, I am sure there are a lot other types of ways you can do this, we do this so it is much easier to find project, assemblies, and build the proper deployments. Plus when looking through your assemblies, seeing full names, rather than "MS.BLL.dll" is a lot more friendly.
项目组件的命名确实没有标准。 重要的是选择适合您的项目的约定,然后一致地应用它。
There really is no standard for naming components of a project. The important thing is to pick a convention that works for your project and then apply it consistently.
您可能会在这里获得一些有关构建包的想法:Java 项目的包结构?
至于方法、接口、变量等......给所有东西起一个名字,准确地描述它的作用或代表什么。 每种语言都有不同的标准命名约定。 您可能想用谷歌搜索您正在编程的语言。
You might get some ideas on structuring packages here: Package structure for a Java project?
As for methods, interfaces, variables, etc....give everything a name that describes exactly what it does or represents. There are different standard naming conventions for every language. You might want to google the language you're programming in.