nus-cs2103-AY2021S1 / forum

20 stars 2 forks source link

Question about inheritance of attribute #519

Closed HCY123902 closed 3 years ago

HCY123902 commented 3 years ago

Hello, can I ask a question regarding inheritance? Given that a class inherits the attribute of another class, will it be necessary to include the inherited attribute in the class diagram?

GeNiaaz commented 3 years ago

If you don't, like in this question

image

A class like Moo which does not include an implemented method for interface Goo would either be abstract or unable to compile.


On the other hand, if Moo did not specify process() , then yes it would inherit the method from its super class Bar. (unless it is inheriting DIRECTLY from an abstract class like Foo, in which case it would have to either instantiate process() or simply be declared abstract itself).

damithc commented 3 years ago

Hello, can I ask a question regarding inheritance? Given that a class inherits the attribute of another class, will it be necessary to include the inherited attribute in the class diagram?

Should not include inherited members unless overridden by that class.

Wincenttjoi commented 3 years ago

@damithc is it considered as strictly incorrect if its put in the subclass when the method is not overriden? (If lets we are asked to choose which options is incorrect)

damithc commented 3 years ago

@damithc is it considered as strictly incorrect if its put in the subclass when the method is not overriden? (If lets we are asked to choose which options is incorrect)

Yes, that would be misleading.

HCY123902 commented 3 years ago

Thank you