Very long class names

后端 未结 7 1581
一个人的身影
一个人的身影 2021-02-18 13:41

I try to name a class (also members, properties and so forth) as exact as I can. But sometimes I’m not sure if this is so clever if the class name becomes huge (50 chars and mor

7条回答
  •  粉色の甜心
    2021-02-18 14:01

    Regarding the example of ProjectContractChargingPeriodProjectAccountReferenceVM, you can refactor it into something like this:

    namespace Project
    {
      public class ContractChargingPeriod implements IAccountReference
      {
        ...
      }
    
      public interface IAccountReference
      {
        ...
      }
    }
    

    The ContractChargingPeriod is dealing with all the business logic related to contract charging periods. The fact that it implements IAccountReference also tells that the object refers to an account, but without specifying this in the class name.

    You can create simple viewmodels that reflect the contents of these types, but the viewmodels themselves should not contain any business logic. The viewmodels can use the same structure as the example above, but should be defined in a separate namespace.

提交回复
热议问题