开发者

Use of the suffix “Type” when naming domain objects

开发者 https://www.devze.com 2023-01-13 23:16 出处:网络
I sometimes see domain object开发者_运维百科s or enums named with a suffix of \"Type\", such as \'ItemType\' or \'PermissionType\'.

I sometimes see domain object开发者_运维百科s or enums named with a suffix of "Type", such as 'ItemType' or 'PermissionType'.

The word is so general and non-specific, I wonder if it is being used more often that it should be.

Are class names like these often produced due to a lack of effort to come up with a more meaningful signifier, or is "Type" really the only option in many cases?


I think the word "Type" is likely at the front of developers' minds, since we deal with types a lot within programming languages. Yes, there are often other options, depending on the situation (e.g. "ItemCategory" instead of "ItemType", "PermissionMode" instead of "PermissionType") but they may not be that much less vague.

If at all possible, I try to use the term that is used by people who work in the domain: i.e. if the folks putting items into packages and mailing them out refer to an item's type, that's the word to use.


When used on a class, it's usually wrong: PermissionType would mean "type for Permissions". It should be just "Permission"

However, I do often see it used on enums --- when the enum is a list of types. i.e. PermissionType does not mean "type for Permissions " but "enum of Permissions types". This would be legitimite.


'Type' is more indicative of the variety and importance of the information.

For example: EmployeeType may refer to pay scale, department, skill level, seniority, etc. or a combination of these factors. You could break these factors out into separate entities with separate names or have combinatorial naming (e.g. SeniorProgrammer) but that may not be worth the noise trade off vs. other more important distinctions.

0

精彩评论

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

关注公众号