Is-a vs Has-a

noun

say it: “IZ-uh ver-sus HAZ-uh” /ɪz ə ˈvɜːrsəs hæz ə/

A quick test for design: if one thing is a kind of another, use inheritance; if it has one, use a field.

What is Is-a vs Has-a?

Is-a vs has-a is a quick test for picking inheritance or composition. A dog is an animal, so inheritance fits. A car has an engine, so composition fits.

In a sentence

  • “By is-a vs has-a, a Car has an Engine, so Engine is a field, not a base class.”

Level: Journeyman · More OOP terms at this level

Updated