开发者

How I know when a class is a Helper or a Service?

开发者 https://www.devze.com 2023-04-10 06:40 出处:网络
i\'m using DDD archit开发者_开发百科ecture in my project and I need to create a class to generate a GUID to use in another class.

i'm using DDD archit开发者_开发百科ecture in my project and I need to create a class to generate a GUID to use in another class.

This class that generate my GUID is a Infrastructure Service or a Infrastructure Helper?

How I know when a class is a Helper or a Service?


Service able to serve some clients, and often this is a SOA specific entity. Helper provides a set of methods which commonly are pure functions.

From my point of view if a class which provides the GUID generation functionality stores or uses this GUID for further needs - it is a Service class, otherwise I would say it is a Helper because simply work by principle do and forget / generate and forget.

Often if you can make method a static method - this is a helper method, it does not depends on any class state and does not affect it as well.


Glad you found an answer but you might want to rethink the question itself. What is 'Helper'? There is no such pattern or stereotype in DDD or anywhere else. Take a look at this answer. [Something]Helper is usually a sign of SRP violation or just a bad naming. For example if your language/framework does not provide Guid generation (which is highly unlikely) you can create your own GuidGenerator class. The name should reflect responsibility.

0

精彩评论

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