Take the 2-minute tour ×

I was once asked in an interview 'What are the 3 main concepts of OOP?'. I answered by saying that in my opinion there were 4 which are as follows:

  • Inheritance
  • Encapsulation
  • Abstraction
  • Polymorphism

Was I correct?

share|improve this question
How did they reply to your answer? –  Joe R Dec 31 '08 at 14:24
Please see also: "Jargon-free comparison OOP vs Procedural": stackoverflow.com/questions/1530868 –  dreftymac Dec 4 '09 at 18:25
Abstraction == Inheritance –  Fahad Uddin Mar 19 '11 at 2:54

15 Answers 15

up vote 39 down vote accepted

There are 3 requirements for a language to be object-oriented:

  • a language that supports only encapsulation (objects) is not object-oriented, but it is modular
  • a language that supports just encapsulation (objects) and message-passing (polymorphism) is not object-oriented, but it is object-based
  • a language that supports encapsulation (objects), message-passing (polymorphism), and inheritance (abstraction), is object-oriented

NOTE: Abstraction is a much more general concept; encapsulation et al are kinds of abstraction, just as a subroutine is a kind of abstraction. See Abstraction

share|improve this answer
A good answer, certainly got my vote. You could maybe improve it by adding a couple of examples for each of the above. –  Shane MacLaughlin Dec 31 '08 at 14:39
These don't make up an object oriented language, a language having all those things is just a language that supports object orientation. A really object oriented language is one where these things are build deeply into the language. –  Rene Saarsoo Dec 31 '08 at 15:16
@[Rene Saarsoo]: define the difference please. –  Steven A. Lowe Dec 31 '08 at 15:20
Yep, there is nothing most programming languages to prevent you from writing huge unstructure monolithic lumps of code. Worse still, some people do ;) –  Shane MacLaughlin Dec 31 '08 at 15:45
How polymorphism is equal to message-passing –  XMen Jan 5 '11 at 12:30

I would say that abstraction is not solely an OOP concept, in that you can abstract to a large degree in many non-OOP languages.

share|improve this answer
Abstraction is in my opinion the most important part of them all. –  Filip Ekberg Dec 31 '08 at 13:54
I was also taught Encapsulation, Inheritence and polymorphism. I know what Abstraction is, of course, but how does "abstraction" apply any more to OOP than to procedural languages? –  Charles Bretana Dec 31 '08 at 14:22
@Filip, I agree it is the most important part of much programming but would ague that it is unique to OOP. Once you can create your own functions and procedures that are solving high level domain specific tasks, you are by definition abstracting. –  Shane MacLaughlin Dec 31 '08 at 14:33
I agree: saying that abstraction is a principle of OOP is like saying that Turing completeness is a principle of OOP. It's true, of course, but if necessary you could let it go without saying and not do any harm. –  Steve Jessop Dec 31 '08 at 14:41
What kind of programming can you do without abstraction? –  Apocalisp Dec 31 '08 at 14:41

The four pillars are as your correctly state

  • Encapsulation.
  • Abstraction
  • Inheritance
  • Polymorphism

Encapsulation deals with containing data, nothing more, nothing less.

Abstraction deals with data abstraction, i.e. is all this data really relevant. Think of a bank which contains information on name, age, address, eye colour, favourite tie, etc. Are eye colour and favourite tie really that relevant to the banks requirements? No. This is abstraction.

Inheritance deals with generalisation. Information which can apply to more than one thing. If something inherits from something then it can be said to be a more specific type of that thing. For example, Animal. A Dog is a type of Animal, so Dog inherits from Animal. Jack Russell is a type of Dog, so Jack Russell inherits from Dog.

Polymorphism deals with things having multiple forms, (poly - morph). Two kinds in programming,

  • Late Binding,
  • You refer to something as it's general type and hence the compiler does not know what to bind at compile time. Think method Overriding.

  • Early Binding

  • You redefine a method using a different signature, i.e. int add(int a, int b) vs double add(double a, double b)

These are essentially the basic principles of Object Orientation. There is a lot of overlap between these and so it is quite important to achieve a clear understanding of what each of these mean.

share|improve this answer

Those are the Four Horsemen as I know them. Maybe they mistakenly lump Inheritance and Polymorphism together.

share|improve this answer
Or its a trick question :P –  Ólafur Waage Dec 31 '08 at 13:57
Indeed. There are really \pi main concepts - I never get the fractional one right. –  duffymo Dec 31 '08 at 15:07

The problem with OOP is that nobody bothered to give a proper, concise, agreed-upon definition. Especially, I'd like to point out that all the aspects you mentioned can well be put into action without the use of object orientation!

Two type systems that do this are the Haskell type system, which, by consense, is generally not regarded to be object-oriented, and C++ templates with template subclassing. However, it could perhaps be argued that template subclassing emulates OOP.

Since template subclassing is not a widely known mechanism, let me give an example from the SeqAn library where it was invented.

String<Char> cstr = "This is a test";
String<Dna, Packed<> > dstr = "GATTACA";

cout << "length(" << cstr << ") = " << length(cstr) << endl;
cout << "length(" << dstr << ") = " << length(dstr) << endl;

Here, String<Char> and String<Dna, Packed<> > are inherited of the “abstract class” String<>. They encapsulate the concept of a string, using completely different methods. They share the polymorphic length method, implemented differently for both concrete types.

share|improve this answer
templates emulate OOP; they provide concise syntax, but they do not reuse code. Instead they expand and bloat the code ;-) –  Steven A. Lowe Dec 31 '08 at 16:02
what you describe, in fact, is called Static Polymorphism in "C++ Templates The Complete Guide". –  Comptrol Mar 7 '09 at 16:49
@Comptrol: no, this is something else. Template subclassing establishes an inheritance hierarchy through base classes and has in fact several additional properties (code reuse) of OOP. Static polymorphism doesn't have this, it's merely an ad-hoc relationship between a priori unrelated types. –  Konrad Rudolph Mar 7 '09 at 20:10

Yes, those are the standard four.

Some people combine abstraction and encapsulation. I'm not sure why... they're not completely orthogonal, but maybe there's enough overlap? There's certainly overlap between inheritance and polymorphism, but it would be hard to combine them, in my mind.

share|improve this answer

Most people would consider that correct, my guess is if they were asking for three it would be Inheritance, Encapsulation and Polymorphism.

I personally find that those three concepts are the real "meat" if you will behind the definition of OOP. And most people take abstraction for granted and lum it in with the others, as really it could be considered part of any of the other three.

When I talk about OOP though I always mention the 4.

share|improve this answer
I would find it hard to leave out "abstraction". That's part of the thrust behind the "new" Domain-Driven Design... to create abstractions that model the world as closely as possible. –  Mark A Johnson Dec 31 '08 at 13:54
I agree with Mitchel, I often hear people lump encapsulation and abstraction in the same boat. –  Kevin Dec 31 '08 at 13:58
@Mark - I agree, as an instructor I stress the four, but sadly not all people put emphasis on abstraction, some see it as "just there. –  Mitchel Sellers Dec 31 '08 at 15:26
I guess it depends how and when you learned to program. I programmed in BASIC, assmebler, Pascal, FORTH, and C long before going anywhere near OOP, and good abstraction was always a design goal. The other three aspects of OOP simply combine to allow much better abstraction. –  Shane MacLaughlin Dec 31 '08 at 15:50

Probably the last three is what they were looking for - inheritance could be argued to be more of a mechanism to help achieve the others, which are higher level goals.

There is not really a correct answer anyway, especially if limited to 'top 3'.

share|improve this answer

You are indeed correct. Here's a reference for ya: http://docs.rinet.ru/KofeynyyPrimer/ch4.htm

share|improve this answer

That's correct.

If you had to provide only one, however, Abstraction it's got to be, for, one way or the other, the rest three is merely Abstraction in action.

share|improve this answer

This [article][1] refers to the three pillars of good code. I found it to be an excellent article positing that encapsulation is the "first principle" of object-oriented design.

"First" principles are fundamental, underlying principles from which all else springs. The author uses the example of the Golden Rule. It's difficult to teach children all the finer points of civilized behavior but if you can get them to understand (and more importantly, practice) the Golden Rule of treating others as you would like to be treated, then they are more likely to "get" all the legal and moral standards we're held to on a daily basis.

So, it follows that if a developer understands encapsulation as a "First Principle" of object-oriented development, all of the other principles will follow in due course.

I don't do the author's content justice but I would definitely encourage people to read it.

For some reason I'm not showing the hyperlink as coming through so here's the URL: http://www.netobjectives.com/files/Encapsulation_First_Principle_Object_Oriented_Design.pdf

share|improve this answer

3 main concepts in OOP:

  • Late binding
  • Concept reusing (not sure about this, anyway: re-using of concepts; avoiding the re-implementation of even the simplest concepts)
  • Abstraction
share|improve this answer
Late binding????? –  erikkallen Dec 31 '08 at 14:57
It was the main feature of smalltalk, and main feature of the kind of OOP smalltalk provided. –  Cheery Dec 31 '08 at 15:29

It could have been a trick question for the interview, but in Computer Science classes these days they teach the 4 Pillars of Object Oriented Programming.

share|improve this answer

A proper answer to the question is: "Please clarify what you mean by Object-Oriented Programming." Oops, that would be telling, because the real question being asked is: "When I say OOP, what do I mean?"

There's no correct answer.

share|improve this answer

It's generally believed that those are the main principles however they had very little to do with why OO was created.

One of the guiding principles was the direct manipulation metaphor. That is creating an object in the program that represented an object from the users mental model. Most of the motivation for creating OO was based in psychology not math/CS as is often believe to be the case these days.

If doubtfull of this take a look at some of the work by Trygve Renskauge. Father of MVC and DCI or James Coplien accomplish author and speaker.

So I'd say you likely gave them an answer close to what they expected whether it's correct depends on where you stand.

share|improve this answer

Your Answer


