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
crudely...
Wikipedia - Object-Based Language
Object-based languages include basically any language that offers the built-in ability to easily create and use objects. There is one major criterion:
Encapsulation. Objects have an API attached to them, typically in such a way that you work with the object more by telling it what to do than by running some function on it.
Most object-based languages define objects in terms of "classes", which are basically blueprints for an object. The class lays out the internal structure of the object and defines the API.
This is not the only way, though. In JavaScript, for example, objects don't really have "classes". Any object can have any properties it wants. And since functions are first-class values in JavaScript, they can be set as properties on the object, and serve as the object's API.
As far as object-based-but-not-object-oriented languages go, a good example would be Visual Basic (not the .net stuff; i'm talking about VB6 and VBA). Classes exist, but can't inherit from each other.
Object-oriented languages are object-based languages that take things a step further. They have built-in support for the two other pillars of OOP:
Inheritance. Objects must have the ability to be (and be viewed as) specializations of some other object. This means, for example, being able to define "Dog" as "Animal that can bark and fetch sticks".
In modern languages, it typically takes the form of one object's class inheriting from another object's class. This is not a requirement, though; contrary to what some people will try to tell you, the definition of OOP does not require classes at all.
Polymorphism. Code must be able to use an object without knowing or caring exactly what type it is.
Most languages (especially statically typed ones) define polymorphism in terms of classes and inheritance. If you have a class B that inherits from A, code that requires a reference to an A can typically take a B instead, but not some class C that isn't related to A. Java also has the interface
keyword, which lets you define a set of behaviors a class must implement. Any object whose class explicitly implements X
, and thus implements the functions defined on interface X, qualifies as an instance of type X.
Other languages, like JavaScript, let you pass any object you like. As long as the object presents the right interface, it doesn't matter exactly what kind of object it is. This is called "duck typing", and it is very nearly the purest form of polymorphism there is.