Should a class validate itself or create another class to validate it?

后端 未结 8 890
梦毁少年i
梦毁少年i 2021-02-01 17:30

Let\'s say I have a class like:

class NavigationData
{
  float roll;
  float pitch;
  double latitude;
  double longitude;
}

and if I want to c

8条回答
  •  半阙折子戏
    2021-02-01 18:24

    I would say it depends. If the class's data is validatable in isolation I would put the method in the class, but if the validation requires a context then I would create a validator class based on some interface.

提交回复
热议问题