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

后端 未结 8 783
梦毁少年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:08

    I'd say have it validate itself as long as the valid values don't depend on what other classes use NavigationData.

    Basically, as long as latitude and pitch has to always be between +/- 90 degrees, and longitude and roll always be between +/- 180 degrees, keep the validator in the class.

    (By the way, what about heading?)

提交回复
热议问题