Object-Oriented Language Vs Object-Based Language

Rasikadindorkar
5 min readMar 12, 2021
title image
title image

This blog helps you to understand the difference between Object-Oriented Language and Object-Based Language. I will explain the differences with examples. Also explaining the OOP’s concepts to understand them in a better way.

What is an Object?
An object is an entity that performs computations that has a state and behavior. We can map an object to a real-world entity. It can be a physical or logical entity.
e.g., Animal, Person, Bank Account, Mobile Device, etc.

What is Class?
Class is a logical entity that is used to create an instance i.e., object. Basically, A class can also be defined as a blueprint from which you can create an individual object. Let’s see an example of class and an object.

In this example, we have created the Class for MobileDevice. using MobileDevice class we can create an individual object.

In the above image, we have created the instance of MobileDevice and mobile is an object. the output of this code snippet is

Visualization for the above example

Object-Oriented Language
A language is said to be an Object-oriented language if
1. it supports objects.
2. it requires objects to belong to a class.
3. it supports all the features of OOPs (Abstraction, Inheritance Encapsulation, Polymorphism).
4. example of Object-oriented language is C++, Java, etc.

What is Abstraction?
Abstraction means hiding the internal details and showing the functionality to the user.
for example ATM, users don’t know internal processing but a user can perform multiple actions through the functionality provided to him.
Similarly phone calls, users don’t know the internal processing of the call but a user can dial the call using functionality provided to him.
let’s understand using the below example,

In above example, you can see we have a public method DialCall and there are two private methods “checkBalanceForDialing” and “routeTheCallonValidNetwork”, when call is initiated or DialCall method is called, internally we are checking that does user have a balance more than 0. if yes then Call will route to the valid network zone in which dialed number is present.
In this example, DialCall method is public hence user can access this method directly but can not access private methods from outside the class.

What is inheritance?
Inheritance is a mechanism in which, one class(child class) acquires all the properties and behavior of another class(parent class).
Terms used in the inheritance
1. Child class: a class that acquiring the properties and behavior of another class
2. Parent class: a class whose properties and behavior is acquired by another class
let's understand by example and diagram

MobileDevice is a parent class whose properties acquired by the child class i.e., NokiaClass.

NokiaClass is a child class that is acquiring all the properties and behavior from the parent class i.e., MobileDevice class.

In the DemoMainClass, we have created the object of NokiaMobile, and you can observe that NokiaMobile object acquiring the properties and behavior from the parent class i.e., MobileDevice class. Inheritance facilitates you to reuse the fields and methods of the existing class when you create a new class.

Visualization of inheritance

What is Encapsulation?
Binding code and data together into a single unit are known as encapsulation.
A java class is an example of encapsulation. “MobileDevice” and “NokiaClass” is an example of encapsulation.

What is Polymorphism?
Polymorphism means one task is performed in different ways as per requirements.
for example, unlocking a mobile device user can unlock the non-android devices by key, android by fingerprint, and iPhone by the face-unlock system. so in this example unlocking is one task but the user will perform it in a different manner depending upon the device type.
let’s understand by example and diagram

This is the generic method that will be overridden by other classes and implement the specific logic according to requirements.

This is the nonAndroidMobile Class and we are implementing the unlockTheMobile method and overriding the generic method.

Here we have created an AndroidMobile class and in this class, we are overriding the generic method from MobileDevice class.

Similarly, we have implemented for iphoneMobile class.

now let’s see the output

here you can see the different behavior of functionality is implemented depending on the different mobile devices.

Object-Based Language
Object-based Language is based on the idea of encapsulating state and operations inside “objects”. it need not support the inheritance or polymorphism.
for example, JavaScript language.
let’s understand with an example, code, and diagram

The above code is javaScript code, we have created class “mobileDevice” and created an object of mobileDevice using a new keyword. but we can not inherit this class as well as can not implement a polymorphism.

Overview of the blog

--

--

Rasikadindorkar

Software Developer | Programming enthusiast | Love to code