Object-oriented – Do non-OOP paradigms support concepts such as encapsulation

functional programmingobject-oriented

One of the important concepts in Object Oriented Programming is Encapsulation. However, lately the software world seems to be tilting in favour of other paradigms like functional programming.

It makes me think, what about encapsulation and other OOP tenets? Are they wrong?

Is it that OOP is applied wrong? For instance Alan Kay is noted for saying in the OOPSLA'97 Keynote: "I invented the term object-oriented, and I can tell you I did not have C++ in mind."

Joe Armstrong – "Objects bind functions and data structures together in indivisible units. I think this is a fundamental error since functions and data structures belong in totally different worlds."

Best Answer

I think the trap you fell into here is thinking that there is a rigid definition of any programming paradigm (structured, object-oriented, functional, et. al.)

If you ask two different developers what OOP means, you will get two different answers. Yes, as a profession we agree that there are a few common themes such as encapsulation, data hiding, etc. covered by any OOP software engineering class in college.

However, in the real world, things are not quite so cut and dry, which is why two developers will give two different answers. Perhaps they are experts in different languages that express OOP concepts differently. Language paradigms tend to overlap. The latest rage as of 2013 or so is incorporating functional programming in object-oriented languages through closures or lambdas. Is Java 8 object-oriented or functional? I would call it object-oriented with a dash of functional. Someone else might describe it differently.

Is it that OOP is applied wrong?

No, the issue is that various languages express programming concepts differently. Perhaps one language leaves out an OOP concept, and another language includes it but leaves out a different OOP concept. Languages are typically designed for a purpose: to make a certain type of task easy, at the expense of making other tasks more difficult. That is neither right nor wrong, it is simply a real-world tradeoff that is impossible to avoid.

The real world is not the classroom. We either need to discuss conceptual programming paradigms at the abstract level, or we need to discuss real programming languages that are forced to make tradeoffs in order to be useful. As long as a programming language is mostly defined by an abstract definition of OOP, we can include it in that bucket.

Related Topic