What is Object-Oriented Programming (OOP)?

If you use classes and objects in your programs, but neither inheritance nor polymorphism, many authors refer to this as "object-based" programming, but insist that it not be called "object-oriented" programming unless you employ inheritance and polymorphism as well.

The Three Pillars of OOP

  1. Encapsulation
  2. Inheritance
  3. Polymorphism

Benefits and Goals of OOP

  1. Natural OOP uses the terminology of the problem, not the terminology of a computer.
  2. Reliable Modular construction puts knowledge and responsibility where they belong, and allows each component to be tested and validated independently.
  3. Reusable Well designed class objects can form reusable components (but of course this is not guaranteed).
  4. Maintainable OOP permits software components to change or even be replaced completely in a way that should be transparent to the rest of the system.
  5. Extendable OOP permits easy addition of new functionality, as the user's needs change over time.
  6. Timely OOP permits quicker development times by allowing parallel development of independent classes by independent developers.

Pitfalls of OOP

  1. Thinking only of the programming language That is, not paying enough attention to everything else that's involved, and then blaming "the technology" when things go wrong.
  2. Thinking of OOP as a cure-all Using OPP does not guarantee success. There is never any substitute for good judgment. Planning, designing and careful coding are always necessary, whatever your approach and however sophisticated your tools may be.
  3. Fearing to re-use code That is, always wanting to start from scratch.
  4. Selfish programming That is, not wanting to share the code you create.

More Details on the Three Pillars

  1. Encapsulation in this context means "putting together the things that should be together, in particular attributes and operations (data and methods).
  2. Inheritance is a hierarchical relationship in which the members of one class are all passed down to any class that descends from (extends) that class, directly or indirectly. It is in this sense that we appear to be "getting something for nothing".
  3. Polymorphism may be regarded as the knock-out punch of OOP, if encapsulation and inheritance are its one-two punches.