Take the 2-minute tour ×
Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. It's 100% free, no registration required.

Specifically, programming without inheritance is distinctly not object-oriented; we call it programming with abstract data types.

I found this great line from Grady Booch's "Object-Oriented Analysis and Design With Applications" book. So in order for a program to be an OO one, are inheritance, abstraction, encapsulation, and polymorphism(?) must-to-be things?

Could anybody please explain me?

share|improve this question

migrated from stackoverflow.com Jan 10 '12 at 19:21

This question came from our site for professional and enthusiast programmers.

3  
Related: All Applications developed using c# are not object oriented? (ignore the C# part) –  Cody Gray Jan 10 '12 at 10:56
    
real men subclass everything –  Boris Treukhov Feb 25 '12 at 9:14

5 Answers 5

up vote 2 down vote accepted

Abstraction and Encapsulation are really the only things required for something to be object- oriented.

Inheritance and polymorphism are strategies to take advantage of NOT "reinventing the wheel" which is a benefit to using OO designs.

The base idea behind OO design is to get a large amount of programmers to work together on project X without incurring massive communication overhead, and breaking a project down into objects with defined communication between them is an elegant solution.

share|improve this answer

Quick Short Answer

The answer is that is very subjective to the Software Analyst or Software Modeler.

Extended Boring Answer

There are several concepts that related or part of the Object Oriented Paradigm. You already mention most of them.

For example, one concept you didn't mention, is message-passing, that is missing in most current O.O. programming languages, and was available, together with encapsulation and inheritance in the early O.O. programming languages ("Simula").

I worked sometimes with several variants or "idioms" of Object Oriented Pascal, that had several of those features, and there was a variant that allowed to use "messages", as part of the programming language (keyword "message"), similar to "try catch" exceptions, but, without interrupting execution.

While, other variants, and other programming languages provided as optional libraries (functions not keywords).

Summary

You may find that sometimes a programming language may skip some of them, and still be considered by some people O.O., while other not. Its very subjective.

Are you asking for plain intellectual curiosity ?

Do you wonder if the programming language you are using, is fully O.O. ?

Are you working with a collegue / university homework custom O.O. programming language ?

Are you working with a hobbyst, pet project, custom O.O. programming language ?

These questions, is my own curiosity, but, also to know how to make my answer more clear ;-)

There are some programming language & programming paradigms comparison courses at collegues and universities, that deal with this subject.

Cheers.

share|improve this answer
    
i am doing my final-semester-project :) yes, the thing is conceptual and it seems no language is fully OO ! –  Prakash Bala Jan 11 '12 at 11:21

Programming with abstract data types means that when you write:

struct A { int i; float k; };

You can use A a; as abstraction of some bits like [00000000][00000000] (with proper number of bits).

Inheritance adds the following feature:

class A { public: virtual void f()=0; };
class B1 : public A { public: void f() { ... } int a; int b; };
class B2 : public A { public: void f() { ... } int i; float k; };
void algo(A &a) { a.f(); a.f(); }
int main() { B1 b; algo(b); B2 b2; algo(b2); }

i.e. When there are several classes like B1,B2,B3 the algorithms like algo() can work with all of them, even if the format of the bits is changing between B1 and B2, like the { int a; int b; } is different from { int i; float k; }. Only f() needs to be rewritten, not the whole algo().

share|improve this answer

You could model any domain without inheritance. Inheritance helps to sometimes be more clear about classes, but it is not a mandatory thing in object orientation, despite Booch's quote.

share|improve this answer
    
Modelling a domain and correctly using object-oriented design are not the same. I posit that designing software of any significant size, using OOD, will require inheritance. –  Steve Evers Jan 10 '12 at 19:29
    
I agree with the idea that designing software of any significant size, using OO, will requiere inheritance, but the question looks like rethorical, and with that context in mind for me is not mandatory the use of inheritance –  JuanZe Jan 10 '12 at 20:32
1  
@SnOrfus object composition will do just as well as inheritance. You don't need inheritance at all. –  Raynos Jan 10 '12 at 22:53
    
@Raynos: I disagree. Without IEnumerable<>, and the collection classes that implement it, for example, things like LINQ wouldn't be possible - or at best, intractable. The old saying favour composition over inheritance isn't, use composition isntead of inheritance. –  Steve Evers Jan 24 '12 at 4:48
    
@SnOrfus depends how composition is implemented. In a dynamic language where you can mix objects into other objects at run-time, composition will just work. –  Raynos Jan 24 '12 at 10:59

Useful quotes from the C++ Faq Lite (don't be annoyed by its relation with C++, the concepts are the same in any OOP language):

"Inheritance is what separates abstract data type (ADT) programming from OO programming."

"Programming with classes but without dynamic binding is called object based, but not object oriented." Note that dynamic binding is another term for polymorphism. Also AFAIK inheritance is necessary to implement polymorphic classes.

So to answer your main question, yes, all the things that you are mentioning are "a must" for writing good OOP code.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.