开发者

Where to define an enum shared by interface and implementation?

I have a project with two namespaces, Interfaces, and Services. Each service implements its corresponding interface. Now I开发者_如何学Go need method declarations to include an enum declared for one service. Which namespace do I put the enum in? If I put it in Services, I need to reference Services in Interfaces, which is just ugly. It would be quite neat to pu it in interfaces, but that's not really where enums belong. Suggestions on where to place this enum will be welcome.


I would recommend a common namespace / assembly referenced by both. Where are your DTOs / Entities defined? This may be the ideal location.


Generally the data access interfaces(repositories) are defined in the same namespace as models. Since the enumeration is a part of the model, it belongs there as well.

Perhaps if you reconsider naming the namespace Interfaces and instead use a more domain specific name - e.g. Clients, Accounts etc, it would feel more natural to define types that interfaces use alongside them.


In our systems we have a namespace/assembly called Entities which contains all the Interface, Type and Enum definitions. This is then referenced from the Server project (which implements the Interfaces) and also by the Client project (which calls the Server via the Interface). This works really well for our requirements.


I would have a common project referenced by both your interface and service projects, which includes types/enums that need to be shared across all projects.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜