1

Should the private methods of a class check if the object is properly initialized even if it's already done by the public methods?

I have an class/object that represents real hardware. What the private methods do can be dangerous if object is not properly initialized. Should these private methods check the initialization status if this is done by the public methods that call those private methods?

  • So you mean that the public methods all do already check the initialisation status before calling any private method? Then yes, you can make that a documented precondition of the private method, and don't need to repeat the check unnecessarily. – Bergi Jul 27 '19 at 21:36

1 Answers1

0

The private methods should assert that the values are initialised, but they don't need to communicate failures to the caller because that is done by the public methods.

RWRkeSBZ
  • 723
  • 4
  • 11