nus-cs2113-AY2324S2 / forum

2 stars 0 forks source link

Inheritance vs Association? #50

Closed JackieNeoCEG closed 1 month ago

JackieNeoCEG commented 1 month ago

Hi!

Can I check if Inheritance is a "special" form of association? I understand that they are catagorised between "is-a" relation and "has-a" relation but I don't know if they have something in common. E.g Suppose Child Class Circle inherited from Parent Class Shape, can I also draw an association pointing from circle to shape in the object diagram?

okkhoy commented 1 month ago

In lay terms, Inheritance is "getting things/behaviors from parent class" Association is maintaining reference of one in another.

WRT your example, nothing prevents you from having an association from circle to shape.

JackieNeoCEG commented 1 month ago

Thank you Prof!