Seite 1 von 1

Ex 5.2 - InsufficientDocumentation

Verfasst: 4. Dez 2017 14:53
von 0b101101101
In the lecture slides it is said that any overridable method must declare use of other overridable methods. However, what about attributes? I believe if a method uses attributes that are modified by overridable methods _or_ can be modified in a subclass, then methods must declare the use of these attributes, too, or else a subclass may simply choose not to modify those attributes in the same way and methods will surprisingly fail.

Re: Ex 5.2 - InsufficientDocumentation

Verfasst: 4. Dez 2017 14:58
von GS-812
I see it the other way, overridable methods must explain, which attributes have to update in case you overwrite them.

Re: Ex 5.2 - InsufficientDocumentation

Verfasst: 4. Dez 2017 15:14
von eichberg
In general, I highly(!!!) recommend to only use private state. However, if you have a non-private instance field you should document the contract (the invariant) related to the field where you define the field. (It may be necessary to update the field in a future subclass in a new method which does not override anything.)