Knowledgebase

Object-Oriented Concepts Compared Print

  • programminglanguages, programming, guide, howto, solution, zillionkinghost, hosting, support
  • 0

Objects across languages.

WHAT THE CORE IDEAS ARE

  • Encapsulation: data and behaviour together, with internals hidden
  • Inheritance: types derived from other types
  • Polymorphism: different types used through a common interface

WHAT VARIES BETWEEN LANGUAGES

Whether classes exist, or objects are built from prototypes Whether multiple inheritance is permitted How interfaces are expressed How access is controlled

WHAT INTERFACES PROVIDE

A contract without an implementation.

WHY THAT MATTERS

Code depends on the contract, not on a concrete type, which makes substitution and testing possible.

WHAT COMPOSITION MEANS

Building behaviour by combining objects rather than inheriting.

WHY IT IS GENERALLY PREFERRED

Deep inheritance hierarchies become rigid, and changes propagate unpredictably.

WHAT THE GUIDANCE IS

Inherit to express a genuine is-a relationship; compose otherwise.

WHAT ENCAPSULATION ACTUALLY ACHIEVES

The ability to change internals without breaking callers.

WHAT DEFEATS IT

Exposing internal state directly.

WHAT TO PREFER

Exposing behaviour, not data.

WHAT TO BE CAUTIOUS OF

Applying patterns where simple functions would serve.


Was this answer helpful?
Back

Are you happy with your experience? Leave us a review on Trustpilot.


Trustpilot