跨业务逻辑层正确设置类访问器?
我的业务逻辑层中有几个类(一些示例);
Atomic.Core.BLL.Client
Atomic.Core.BLL.Airport
Atomic.Core.BLL.Airline
在每个类上设置访问器时,我有时想引用 BLL 中的对象(因为它们是相互链接的),但我想高效地做到这一点,而且还可以使用最佳实践。
我想做这样的事情:
using System;
using System.Data;
//removed for brevity
namespace Atomic.Core.BLL.Airport
{
public class Airport
{
private int airport_id = 0;
public int AirportId
{
get { return airport_id; }
set { airport_id = value; }
}
private Airline airline = null;
public Airline Airline
{
get { return airline; }
set { airline = value; }
}
}
}
Visual Studio 说我的 AirlineObject
是一个用作类型的命名空间,我完全理解这一点,那么我可以将 Airline 添加到“使用”列表中并简写它吗?我该怎么做? 使用 Atomic.Core.BLL.Airline 作为航空公司
?我不记得了!另外,我是否错过了重点,我是否应该重新思考我想要做什么?
帮助(一如既往)表示赞赏。
I have several classes within my business logic layer (some examples);
Atomic.Core.BLL.Client
Atomic.Core.BLL.Airport
Atomic.Core.BLL.Airline
When setting up the accessors on each class, I want to sometimes refer to objects within the BLL (as they are interlinked), but I want to do it efficiently and moreover with best practice.
I want to do something like this:
using System;
using System.Data;
//removed for brevity
namespace Atomic.Core.BLL.Airport
{
public class Airport
{
private int airport_id = 0;
public int AirportId
{
get { return airport_id; }
set { airport_id = value; }
}
private Airline airline = null;
public Airline Airline
{
get { return airline; }
set { airline = value; }
}
}
}
Visual Studio says that my AirlineObject
is a namespace being used as a type, which I totally understand, so can I add Airline to the Using list and shorthand it? How do I do that? using Atomic.Core.BLL.Airline as Airline
? I can't remember! Also, am I missing the point here and should I re-think what I am trying to do?
Help (as always) appreciated.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
最佳实践 - 不要命名命名空间和具有相同名称的类。原因?以下是一些:
https://learn.microsoft.com/en-us/archive/blogs/ericlippert/do-not-name-a-class-the-same-as-its-namespace-第一部分
https://learn.microsoft.com/en-us/archive/blogs/ericlippert/do-not-name-a-class-the-same-as-its -namespace-part-two
https://learn.microsoft.com/en-us/archive/blogs/ericlippert/do-not-name-a-class-the-same- as-its-namespace-part- Three
Best practice - do not name namespace and a class with the same name. Reasons? Here are some:
https://learn.microsoft.com/en-us/archive/blogs/ericlippert/do-not-name-a-class-the-same-as-its-namespace-part-one
https://learn.microsoft.com/en-us/archive/blogs/ericlippert/do-not-name-a-class-the-same-as-its-namespace-part-two
https://learn.microsoft.com/en-us/archive/blogs/ericlippert/do-not-name-a-class-the-same-as-its-namespace-part-three
https://learn.microsoft.com/en-us/archive/blogs/ericlippert/do-not-name-a-class-the-same-as-its-namespace-part-four
使用航空公司= Atomic.Core.BLL.Airline;
using Airline = Atomic.Core.BLL.Airline;
我不会将所有 BLL 类都放在自己的命名空间中。将它们全部转储到 Atomic.Core.BLL 中,或者如果您需要更具体,则将它们转储到 Atomic.Core.BLL.AiportLogic 的一个小节中。
I wouldn't have all BLL classes in their own namespace. Dump them all into Atomic.Core.BLL, or a subsection - Atomic.Core.BLL.AiportLogic - if you need to be more specific.