I want to know what is the core difference between
Object Oriented and Object based languages
I have read many post all of them are saying
Just using objects does not mean you are doing OOP, even in a fully OO language if you are not implementing OO techniques it is simply object-based programming.
Object orientd language
Object-orientd language supports all the features of OOPs
Object-orientd language does not has in-built object
Object-orientd languages are C++, C#, Java etc
Object based language
Object-based language doesn't support all the features of OOPs like Polymorphism and Inheritance
Object-based language has in-built object like JavaScript has window object.
Object-based languages are JavaScript, VB etc.
Hope, this will clarify your doubt.
OOP and OBP are types of programming languages follows different principles.
OOP : follows Polymorphism, Inheritance and Encapsulation(PIE).
OBP : follows Polymorphism and Encapsulation.
Object oriented programming languages follow all concepts belonging to OOP.
Object based programming language has objects ibuilt so there's no need to create objects and it also follows OOP concepts except inheritence,
JavaScript is a prototype-oriented language.
It can build actual objects from a constructor function and it has almost any feature that any object could have:
In JavaScript, any object has a prototype, including functions. The prototype itself is a rudimentary way of adding object members to any newly created instance of the whole object.
var constructor = function() { };
constructor.prototype.text = "hello world";
alert(new constructor().text); // This alerts hello world
Why JavaScript isn't an object-oriented programming (scripting) language? Because it has no feature that fits the requirements of the definition of object-oriented programming:
Perhaps I forgot to mention some other detail, but I honestly believe that this is a good summary.
The core difference is an object-oriented programming language has the features that an object-oriented paradigm must have in order to be considered an object-oriented programming language. Thus, JavaScript, for now, isn't an actual object-oriented programming language because it lacks actual polymorphism and inheritance.
Esthetically speaking yes, ES2015 and above has a major improvement that let consider a not fully but more closer to an object-oriented programming: syntactic sugar to call to the super class.
For example:
class A {
doStuff() {
console.log("hello world");
}
}
class B extends A {
doStuff() {
super.doStuff();
console.log("...and goodbye!");
}
}
This is polymorphism. A more specialized class can override its base class to both completely change a function behavior or do what the base was already doing, adding new code to the function.
BTW, ES2015 and above still lacks true encapsulation: where are access modifiers like private
or public
here? Nowhere.
And, at the end of the day, ES2015 and above implement class-based OOP but it's still a syntactic sugar layer on top of ECMAScript 5.x... The above code still works with prototypes under the hoods and it works the same way as if you would code it in ECMAScript 5.x:
function A() {
}
A.prototype.doStuff = function() {
console.log("hello world");
};
function B() {
}
B.prototype = Object.create(A.prototype);
B.prototype.doStuff = function() {
A.prototype.doStuff.call(this);
console.log("...and goodbye!");
};
Let's hope I'll need to update this answer again because ES2020 has already proposed access modifiers and we'll be able to consider JavaScript another language which fully-supports object-oriented programming!
There are 4 major elements that a Programming Language must conforms to in order to be a true object-oriented language. These are: Abstraction, Encapsulation, Modularity & Hierarchy.
However, we can call a Language Object based if that supports the first there elements. As soon as a programming language supports the concept of Object, inherently it supports the first three elements as they are inherent feature of an Object.
JavaScript as a language can not be said a Object Oriented but Object Based Language as it doesn't support Hierarchy (especially Inheritance).