3

當涉及utils和其他幫助類時,我有問題正確地命名我的類和服務。命名空間和類名稱準則

你會如何構建如下:

EventService.cs 
EventServiceUtils.cs 
EventServiceValidators.cs 
EventServiceCoordinator.cs 

等等

我有同樣的需求作爲上述服務的多個服務。 一個想到的就是這一切的分成合適的命名空間,使得它看起來是這樣的:

Services.EventService.EventService.cs //(the actual service) 
Services.EventService.Validators.DateValidator.cs 
Services.EventService.Validators.ParticipantValidator.cs 
Services.EventService.Coordinators.ParticipantCoordinator.cs 
Services.EventService.ExtensionMethods.Extensions.cs 

等。每個命名空間當然是一個單獨的文件夾。 但是這並不是100%,因爲在其他服務中可能會有更多的DateValidator,這很容易導致不需要的引用。

而且Services.EventService.EventService.cs也在命名空間中包含類名,這也是不好的。您可以使用Services.Event.EventService.cs,但當然已經有一個具有該名稱的實體。

這是域模型。

回答

1
AppName.Services.Events.EventService.cs //(the actual service) 
AppName.Services.Events.ParticipantValidator.cs 
AppName.Services.Events.ParticipantCoordinator.cs 
AppName.Validators.DateValidator.cs 
AppName.Text.Extensions.cs 

點:

  • 添加擴展到命名空間描述他們正在擴展
  • 加入通用的校驗做一般的命名空間
  • 使用應用程序的名稱作爲頂級(Microsoft建議公司名稱按照他們的指導原則)
  • 如果只有少數人,我不會把協調員放在單獨的名稱空間中。

微軟指南可以在這裏找到:Framework Design Guidelines

1

你可以把驗證(其他類)是在多個服務使用名爲例如單獨的命名空間。 CommonValidators。
您可以更改名稱EventService.cs而不是更改名稱空間的名稱 - 也許Main.csDefault.cs
我認爲你的服務在接口中有一個合同,所以這將表明服務合同的主要/默認實現。

相關問題