Core difference between object oriented and object based language

后端 未结 8 1838
天涯浪人
天涯浪人 2020-12-12 17:05

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

相关标签:
8条回答
  • 2020-12-12 17:50

    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.

    0 讨论(0)
  • 2020-12-12 17:53

    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.

    0 讨论(0)
  • 2020-12-12 17:54

    OOP and OBP are types of programming languages follows different principles.

    OOP : follows Polymorphism, Inheritance and Encapsulation(PIE).

    • Examples: Java, .Net so on. OOP is new comparing with OBP

    OBP : follows Polymorphism and Encapsulation.

    • Examples: Ada, Visual Basic (VB), and Fortran 90. OBP is old
    0 讨论(0)
  • 2020-12-12 17:56

    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,

    0 讨论(0)
  • 2020-12-12 18:04

    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:

    • Constructor.
    • Methods (i.e. functions in JavaScript).
    • Properties (since ECMA-Script 5, "getters/setters").
    • Instances.

    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:

    • Polymorphism: No. You can change the behavior of a prototype member, but this is just reusing the identifier. You aren't able to access the previous implementation of the member in a pseudo-derived object.
    • Inheritance: Not at all. Maybe prototype chain might be comparable to inheritance but JavaScript (ECMA-Script 5.x or earlier versions) has no syntax-based inheritance like other OOP-based languages (i.e. Java, C#, Ruby, Python, VisualBasic.NET, ...).
    • Encapsulation. Yes, of course, but there's no way to create actual private or internal object members.

    Perhaps I forgot to mention some other detail, but I honestly believe that this is a good summary.

    Update and 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.

    Update: Does ES2015 and above changed the situation?

    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!

    0 讨论(0)
  • 2020-12-12 18:04

    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).

    0 讨论(0)
提交回复
热议问题