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.

I had a discussion about OO programming today and by browsing the internet I found a lot of different specifications for object oriented languages.

  • What are the requirements for a language to be object oriented? For myself an object oriented language must have classes, inheritance and encapsulation.
  • Is C an object oriented language just because you can use structs and program with an object oriented design? Why/ why not?

Are there any good sites/articles about this? And please, no Wikipedia links because I've already been there.

share|improve this question
6  
Who said that "object-oriented" is well-defined? –  delnan Mar 19 '12 at 17:38
4  
Smalltalk is the purest form of OOP –  Raynos Mar 19 '12 at 17:39
2  
This is at least 3 questions which could all be answered separately. You might want to consider asking three independent and better focused questions because someone trying to answer you might only be able to answer one or two of the many questions you ask. –  FrustratedWithFormsDesigner Mar 19 '12 at 17:41
1  
@Raynos: Alan Kay, the creator of Smalltalk, would probably disagree. He says that the important thing about OO is messaging, and that Smalltalk unfortunately overemphasizes objects and even more so classes over messages. In particular, he now seems to consider adding classes to Smalltalk a mistake. At least, his current project doesn't have classes. –  Jörg W Mittag Mar 19 '12 at 22:55
    
@JörgWMittag: I'd be careful about putting words in Alan Kay's mouth. ;-) Objects are, at least from one perspective, tools to enable messaging. You need something to hold state and behaviour, otherwise messaging is pointless. How you use the objects and messages and where you put the emphasis is where Alan believes Smalltalk took a wrong turn from what I understand - feel free to educate me though ;-). I believe Raynos' point was that in Smalltalk, everything is an object unlike, say, Java, where primitives, for instance, are not. –  Amos M. Carpenter Mar 20 '12 at 0:54
add comment

5 Answers

up vote 5 down vote accepted

OO is usually "defined" in terms of four basic requirements:

  1. Abstraction
  2. Encapsulation
  3. Modularity
  4. Hierarchy

Abstraction means you're able to separate an objects externally visible behavior from its implementation.

Encapsulation means being able to hide the details of the implementation of an object (so closely related to abstraction that some authors treat them as one, leaving only three major requirements).

Modularity means being able to package abstractions into discrete units.

Hierarchy is a ranking or ordering of abstractions -- an ability to define the relationship between one abstraction and another.

I, for one, would consider a language object oriented if it supports these four major requirements. Supports, however, goes a bit beyond "allows" or "tolerates".

C, for example, provides enough flexibility that you can simulate each of these reasonably well. C, however, provides only a little support for abstraction or modularity, and none at all for encapsulation or hierarchy -- you can do these things if you want to badly enough, but the language doesn't really provide any direct support for them.

C++, for an obvious comparison does provide direct support for each of these requirements. Just for example, encapsulation is directly supported by making class members private and/or protected and hierarchies are supported via class inheritance.

That's still not what would normally be called a "pure" object oriented language though. In a pure OO language (e.g., Smalltalk), you not only get support for hierarchy, but you get a pre-defined hierarchy of types, and you have to define the relationship of any new type to some existing type in that hierarchy (i.e., all your code most be in classes, and each class must derive from some existing one).

Although classes and inheritance are both common to many implementations of object orientation, neither is really necessary to it. Just for example, Self and JavaScript both use exemplar-based hierarchies. Instead of a hierarchy of classes, with each object an instance of a class, these just use a hierarchy of objects, with each based on some other object, but modified to some arbitrary degree.

share|improve this answer
    
@Giorgio: No, it doesn't -- not by itself. You need direct support for all four of those for object orientation. Any one by itself doesn't work. Ada 83 (for one example) supports three of the four (all but hierarchy). That's enough that it's typically called "object based", but not "object oriented". –  Jerry Coffin Mar 19 '12 at 18:20
    
I deleted my question because after reading your answer I realised you state that encapsulation is a requirement, but not a feature that is unique to OO. Since you have answered, I repeat my question: I was doubting whether encapsulation identifies OO, since it is also present in procedural and functional languages. –  Giorgio Mar 19 '12 at 18:26
    
It's not true that C does not provide direct support for hierarchy- it actually does. The C Standard specifies that a pointer to a struct may be converted to a pointer to it's first element by simply casting the pointer- which is hierarchical. –  DeadMG Mar 19 '12 at 18:52
    
@DeadMG I think the implication is support for object hierarchy. –  Michael K Mar 19 '12 at 18:57
    
@DeadMG: That's not (even close to) direct support for expressing a hierarchy of abstractions. It's nearly a perfect example of sufficient flexibility to simulate what's needed without supporting it directly. –  Jerry Coffin Mar 19 '12 at 19:22
show 4 more comments

According to Rumbaugh et al., "Object-Oriented Modelling and Design", objects are characterized by the following features:

  • Identity: data is quantized into discrete, distinguishable entities, called objects.
  • Classification: objects with the same structure and behaviour are grouped together to form classes.
  • Polymorphism: the same operation (an operation with the same name) may behave differently on different classes.
  • Inheritance: sharing of attributes and operations among classes based on a hierarchical relationship.

According to this definition, an OO-language should support these concepts natively. In C you can define struct's which share structure, but not behaviour (structure classification without behaviour classification). You can define identity by means of handles to data objects (pointers). Polymorphism and inheritance are missing altogether and must be implemented through ad-hoc techniques.

So, according to these criteria, C is not an object-oriented language. Using some ad-hoc techniques you can implemented and object-oriented design in C, but C does not have enough concepts to support it directly.

share|improve this answer
add comment

The only realistic requirement for a language to be OOP is that it's possible to expend at least a good proportion of the time actually dealing with OOP instead of hacking around it's deficiencies. Something like e.g. C is hardly great, but it's usable. If you're desperate.

Which programming languages are purest OOP? Which denominations are the purest Christians? There's no way you could possibly get a correct or objective answer to that question- there's not even any useful definition of "pure". And secondly, even if you could pick the language which had no other non-OOP features and was "pure" in the scientific definition, i.e., only of one thing, then it would be a terrible language. OOP is not some wonder-child, it's not good for everything by miles, and only offering OOP sends a language right down the pile of awful.

share|improve this answer
add comment

Liskov substitution principle is pretty much the defn of Object Orientated.

Although in practice encapsulation and data hiding are probably more useful

share|improve this answer
add comment

It's hard to tell what it means for a language to be object-oriented. Actually, it's hard to tell what it means for a language to be X, where X can be OO, FP, anything.

The official definition of Object-Orientation is

  • messaging,
  • local retention and protection and hiding of state-process, and
  • extreme late-binding of all things

But note that this describes properties of a program, not a language.

Personally, I would say that a language is object-oriented if it facilitates and encourages building programs that satisfy the above definition. Saying that a language is OO if it allows that, is pointless: every Turing-complete language allows everything. The question is: how easy is it to use?

C certainly allows functional programming. And object oriented programming. And logic programming. But none of these is easy in C, nor does C facilitate or encourage programming in those styles.

Also, note that the above definition doesn't mention anything about classes. Why would it? After all, it's called OOP, not COP. In fact, it doesn't even mention objects! Alan Kay himself says that he regrets calling it object-oriented, and that he should rather have called it message-oriented instead, since the important thing are messages, not objects (and certainly not classes).

share|improve this answer
    
The definition above does not mention objects, but how would you call the senders and receivers of messages? –  Giorgio Mar 21 '12 at 19:55
add comment

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.