108
0

# Features of Object Oriented Language or Paradigm

108
0

This article is all about the features of object oriented language. Object-oriented programming groups operations and data into modular units called objects and combine objects into structured networks to form a complete program. In an object-oriented programming language, objects and object interactions are the basic elements of design. Every object has both state (data) and behavior (operations on data). In that, they’re not much different from ordinary physical objects. It’s easy to see how a mechanical device, such as a pocket watch or a piano, embodies both state and behavior. But almost anything that’s designed to do a job does too. It’s the resemblance to real things that gives objects much of their power and appeal. They can not only model components of real systems but equally as well fulfill assigned roles as components in software systems. Object-oriented language does not work around a single component or unit. It uses a vocabulary more than procedural language. It is a group of all the elements or components linked with the object approach.

The different concepts or elements or sets or components of object-oriented language are:

1. Object
2. Classes
3. Inheritance and class hierarchy
4. Polymorphism
5. Encapsulation (Data Encapsulation)
6. Abstraction
7. Dynamic Binding
8. Message Passing
9. Reusability

### > Object

The single most important feature of an object-oriented language is an object uniquely identifiable by a name. To understand the class, the concept of the object should be clear in object oriented programming.

In object oriented system, an object is a run-time entity. The result of Object Oriented Programming displays many real-world objects. All living and non-living things can be treated as an object so all nouns can be used as an object.

Every object has some attributes and functions (behavior). Objects are further subdivided into physical objects and logical objects. For example, a person, a place, a bank account, a table, a chair, etc. are physical objects. The physical object has physical attributes and can be used for any real-life purpose according to the problem occur and the requirement of the question. Logical objects are rarely used, for example, files or data processing in the computer system are logical objects. C++ programming deals with physical objects and works with logical objects. The behavior of any physical object also describes its logical existence in the problem. A complete view of the physical and logical object is shown in the figure below:

The object may be concrete or conceptual and can be used locally or globally. The object is an item and can be used for any purpose and at any time.

Definition (Object):

An Object is a logical entity containing data and code that manipulates that data.

Or

An object is an instance of a class. It can be uniquely identified by its name and it defines a state which is represented by the values of its attributes at a particular time.

Or

An Object is an entity that stores data and performs actions according to usability.

Or

An object is a software bundle of related states and behavior.

An Object is an instance of a Class. When a class is defined, no memory is allocated but when it is instantiated (i.e. an object is created) memory is allocated. The declaration of an object is the same as declaring a variable for the structure. In general, an object is similar to defining a variable of different types. Whether a variable or an object, memory space is set aside at the time of declaration, not at the time of definition. The state of the object changes according to the methods which are applied to it. The behavior of an object is defined by the set of methods that can be applied to it.

Objects communicate with other objects through their functions. The data or attribute of an object is called member data, and the object’s action, function, or behavior (that an object knows how to do) is called member function. Member data is very similar to variables used in procedural programming but member data can not be accessed directly by other objects. It can be accessed if the object gives permission for accessing the data. Actually, member data keeps its importance and valve over the life of an object. When a program is executed, the object interacts by sending messages to one another. For example, if “student” and “roll-no” are the two objects in a program, then the “student” object may send a message to the “roll-no” object that contains data and code to manipulate the data. Objects can interact without knowing details of each other’s data or code.

### > Classes

A class is described as a group of similar objects. A class may consist of a single object. The digits 0-9, alphabet or letter (A-Z or a-z) and special characters belong to the character-set class. A class can define an unlimited number of objects. A class is a template and can be used for different wizards to handle objects. In other words, it is a reference copy for the object. As objects combine data and function, classes represent both data and function and manipulate it.

Definition (Class):

A class is the implementation of an abstract data type (ADT). It defines attributes and methods which implement the data structure and operations of the ADT, respectively.

Or

Classes are an expanded concept of data structure that handles data members and operates with a member function or function as a member.

Instances of classes are called objects.

Consequently, classes define the properties and behavior of sets of objects. Note that in OOP, Objects are instances (samples) of classes. The entire set of data and code of an object can be made a user-defined data type with the help of a class. Objects are variables of class type. Note that once a class has been defined, we can create any number of objects related to that class. So a class is a collection of objects of similar type. For example apple, orange and mango are members of the fruit class. It can be represented as:

Class-name      obj1, obj2 .... objn;

Here obj1, obj2 ….. objn are different objects of similar class.

For example:

fruit apple, orange, mango;

It will create apple, orange, and mango different objects linked to the fruit class.

A program can have more than one object of the same kind. The program that models water usage, for example, might have several Faucets and WaterPipes and perhaps a handful of Appliances and Users. Objects of the same kind are said to belong to the same class. All members of a class are able to perform the same methods and have matching sets of instance variables. They also share a common definition; each kind of object is defined just once. In this, objects are similar to C structures. Declaring a structure defines a type. For example, this declaration

struct student
{
char name[20];
int rolllno;
}

defines the struct student type. Once defined, the structure name can be used to produce any number of instances of the type:

struct student a, b, c, d;
struct employeee x,y;
struct bank bb, cc;

Similarly, defining an object creates a template for a kind of object. It defines a class of objects. The template can be used to produce any number of similar objects–instances of the class. For example, there would be a single definition of the Faucet class. Using this definition, a program could allocate as many Faucet instances as needed.

A class definition is like a structure definition in that it lays out an arrangement of data elements (instance variables) that become part of every instance. Each instance has memory allocated for its own set of instance variables, which store values peculiar to the instance. However, a class definition differs from a structure declaration in that it also includes methods that specify the behavior of class members. Every instance is characterized by its access to the methods defined for the class. Two objects with equivalent data structures but different methods would not belong to the same class.

Difference between Structure and class

The default member and base class access specifies are different in the case of C++ struct and C++ class. This is one of the commonly misunderstood aspects of C++. Believe it or not, many programmers think that a C++ struct is just like a C struct, while a C++ class has inheritance, access specifiers, member functions, overloaded operators, and so on. Actually, the C++ struct has all the features of the class. The only differences are that struct defaults to public member access and public base class inheritance, and a class defaults to the private access specified and private base class inheritance. The following are the major points discussed before declaring a class or structure within object oriented programming:

 Structure Class 1. The keyword is struct. 1. The keyword is class. 2. It contains data members. 2. It contains data members and function members. 3. All the members are public by default. 3. All the members are private by default. 4. The variable is used to access the members. 4. An object is used to access the members. 5. It is less efficient. 5. It is more efficient. 6. It has a slow processing module. 6. It has a fast processing module. 7. It is less used in C++. 7. It is more used in C++. 8. It has no access specifier. 8. It has an access specifier. 9. There is no term like constructor and destructor for structs. 9. But for class compiler creates a default if it is not provided. 10. It takes more memory as compared to a class. 10. It takes lesser memory for execution.

### > Inheritance and class hierarchy

In the living organism’s system, inheritance occurs. As each person inherits some genes from his ancestors and also passes on some genes to the descendants. There is a parent class or base class, which denotes a class from which a child class or a derived class inherits its features. But why would we want to use inheritance in programming? Well, in the same way, that a lot of DNA is shared between a mother and a child, a lot of code can be shared, or rather, reused. The idea of inheritance is derived from the classes. Inheritance is the process by which objects of one class acquire the properties of objects of another class. It is in hierarchical order. For example, a crow is a flying bird that is a further part of a bird. In other words, classes have sub-classes, and so on. For example, the class of animals is divided into living organisms (human beings, animals, insects, birds, etc.). So it can be seen that each sub-class shares common characteristics with the class from which it is derived.

Definition (Inheritance):

Inheritance in Object Oriented Programming can be described as a process of creating new classes from existing classes.

Some of the essential advantages of inheritance are:

1. Real-life object model: It supports a development model that is closer to a real-life object model with hierarchical relationships
2. Reusability: It provides the facility to use public methods of a base class without rewriting the same.
3. Extensibility: Inheritance provides the facility of extending the base class logic as per the business logic of the derived class
4. Elimination of redundant code: It also reduces or even removes the redundant code.
5. Data hiding: With the help of inheritance base class can decide to keep some data private so that it cannot be altered by the derived class

There are five types of inheritance. These are

• Single inheritance
• Multiple inheritance
• Multilevel inheritance
• Hierarchical inheritance
• Hybrid inheritance.

> Single Inheritance:

A derived class inheriting from a single base class is called single inheritance. In simple words, it has one base and one derived class.

> Multiple Inheritance:

A derived class inheriting from multiple base classes is called multiple inheritance. For example, consider the following case in which class C is derived from both class A and class B depicting the concept of multiple inheritance. In this case, there are two base classes and one derived class.

> Multilevel Inheritance:

A derived class inheriting from a class that inherits from another class is called multilevel inheritance. In this case, there is more than one base class and more than one derived class but one at a time.

> Hierarchical inheritance:

The number of derived classes inheriting from a single base class is called hierarchical inheritance. In this case, there is one base class and two or more derived classes.

> Hybrid Inheritance:

A derived class inheriting from multiple base classes and multiple base classes inheriting from a single base class is called hybrid inheritance. Basically, a hybrid inheritance is the combination of two or more different types of inheritances.

From the concept of inheritance, the user can draw or design a class hierarchy. It means object oriented programming defines a hierarchy of different classes and subclasses within it. One class can be derived from another class. Class hierarchy also describes the relationship between classes and subclasses. Also, the level of inheritance can be viewed from the class hierarchy. It helps the programmer to scan minutely a small number of categories instead of a large number. Also, coding can be shared by using the concept of inheritance and class hierarchy.

Inheritance is somewhat similar to using functions to simplify a traditional procedure. program. If there are three different sections of a procedural program having the same procedure, then the common elements of these three sections can be extracted and put into a single function. So these three sections of the program can call this function to execute the common actions and they can perform their own individual processing as well. Similarly, a base class in OOP contains elements common to a group of derived classes. As function does in a procedural program, inheritance shortens an object oriented program and clarifies the relationship among program elements. Inheritance uses the concept of reusability. The reusability in inheritance means the user needs not to start from scratch when he writes a new program.

### > Polymorphism:

Polymorphism is a feature of OOPs that allows many different types of objects to perform the same operation by responding to the same message. It is the ability to take many shapes or forms. Polymorphism helps the programmer to call different functions with a single statement. It is very close to inheritance. In this user can call member functions for an object without specifying object type. Poly means “many” and morphism means “forms” so polymorphism means “many forms”. Also, Polymorphism means the ability to take more than one form so an operation may exhibit different behavior in different instances (one thing with several distinct forms). Polymorphism means two objects can respond to the same message in different ways.

Definition (Polymorphism):

This ability of different objects to respond, each in its own way, to identical messages is called Polymorphism.

Or

Polymorphism means that a call to a member function will cause a different function to be executed depending on the type of object that invokes the function.

Or

Polymorphism means that some code or operations or objects behave differently in different contexts.

For example consider an example where a teacher meets a person “Karan” who call him a student, his friends call him a friend, his parent call him a son and his sister call him brother. Now here person “Karan” remain the same but behaves differently when he is meeting different persons and accordingly he is taking different forms.

Polymorphism results from the fact that every class lives in its own namespace. The names assigned within a class definition won’t conflict with names assigned anywhere outside it. This is true both of the instance variables in an object’s data structure and of the object’s methods:

• Just as the fields of a C structure are in a protected namespace, so are an object’s instance variables.
• Method names are also protected. Unlike the names of C functions, method names aren’t global symbols. The name of a method in one class can’t conflict with method names in other classes; two very different classes could implement identically named methods.

Method names are part of an object’s interface. When a message is sent requesting an object to do something, the message names the method the object should perform. Because different objects can have different methods with the same name, the meaning of a message must be understood relative to the particular object that receives the message. The same message sent to two different objects could invoke two different methods. The main benefit of polymorphism is that it simplifies the programming interface. It permits conventions to be established that can be reused in class after class. Instead of inventing a new name for each new function added to a program, the same names can be reused. The programming interface can be described as a set of abstract behaviors, quite apart from the classes that implement them.

Polymorphism has overloading and virtual function classifications. Also, the virtual functions can be simple virtual functions or pure virtual functions. Overloading is of two types function overloading and operator overloading like unary operator overloading, arithmetic operator overloading, assignment operator overloading, and binary operator overloading. For example, If “+” is an operator, then it can be used for two different forms firstly it can concatenate two different strings (character data) “Raj” and “Kumar” as “Raj” + “Kumar” and create a combined string “Raj Kumar”. Similarly, the “+” operator can be used to find the sum of two different integer values as 5+3 results in 8.

In the below figure, the different classifications of the polymorphism in the hierarchical order are shown:

### > Encapsulation (Data Encapsulation):

Encapsulation is used to enforce the principle of data hiding. With encapsulation, the fields defined inside a class are accessible to all the methods defined inside the same class, but cannot be accessed by methods outside that class. Before OOP, if there are two procedures that needed to operate on the same piece of information, then either the data is made publicly accessible – and risk accidental data corruption as a result of a bug in someone else’s code or the data has to pass as an argument to each of the functions that operated on it, a tedious and error-prone practice. With encapsulation, all of the methods in an object can get the data, but it is still protected from outside access.

Encapsulation is also called information hiding. It consists of separating the external aspects of an object from the internal implementation details of the object which are hidden from other objects hence data is not accessible to the outside world and only those functions which are wrapped in the class can access it. In other words, the wrapping up of data and functions into a single unit (called class) is called Encapsulation. It prevents a program from becoming so interdependent that a small change has massive ripple effects. Encapsulation is not unique to OOPS. It has a good ability to combine data structure and behavior in a single entity.

Definition:

Encapsulation is the inclusion of one thing within another thing so that the included thing is not apparent.

In C++, a function is clearly encapsulated; its implementation is inaccessible to other parts of the program and protected from whatever actions might be taken outside the body of the function. Method implementations are similarly encapsulated, but, more importantly, so are an object’s instance variables. They’re hidden inside the object and invisible outside it. The encapsulation of instance variables is sometimes also called information hiding. It might seem that hiding the information in instance variables would constrain the freedom of a programmer. Actually, it gives you more room to act and frees you from constraints that might otherwise be imposed. If any part of an object’s implementation could leak out and become accessible or a concern to other parts of the program, it would tie the hands both of the object’s implementer and of those who would use the object. Neither could make modifications without first checking with the other.

Note that Encapsulation gives the more clear result and is more powerful than conventional language that separates the data structure and behavior. Encapsulation is defined by Sebesta as “A grouping of subprograms and the data they manipulate.” In other words, ANSI has proved encapsulation as “the wrapping up of data and function in a single unit (single unit is called class)”. Encapsulation is very close to abstraction. Encapsulation in BASIC, FORTRAN, and C is the grouping of the subprograms or modules into one entity. Here all the external files and functions would be encapsulated.

Actually, Encapsulation is a technique of hiding the internal operations of a class to support abstraction. Here data is hidden and cannot be accessed directly. Note that a class has two major facts. One is public visibility and the second one is private visibility. Public visibility means a class can perform certain tasks, whereas private visibility is the step taken by the class to perform that tasks. It means Encapsulation permits accessing of data only through calling the functions. So these functions provide the interface between the object’s data and the program. This insulation of the data from direct access by the program is called data hiding.

### > Abstraction or Data Abstraction

Abstraction is one of the powerful paradigms of OOPs. It is very close to Encapsulation. It is the concentration on the most essential aspect of the problem and ignoring the details.

Definition:

Implementing real-world entities into the program is called Abstraction.
Or
Abstraction is a process of mimicking a behavior.
Or
Simplifying complex reality by modeling classes appropriately to problem.
Or
Abstraction is a process that involves identifying the crucial behavior of an object and eliminating irrelevant and tedious details.
Or
It is the description of the real world.

Classes use the concept of abstraction and are defined as a list of abstract attributes such as size, weight, cost, and functions to operate these attributes. Abstraction refers to the act of representing essential features without including background details or explanations. Data abstraction is concerned with separating the behavior of a data object from its representation or implementation. For example, a stack has four operations Push, pop, full and empty. As the user uses these operations but has no knowledge about how the stack is actually implemented. So because the underlying implementation of the data object is hidden from its users, the implementation can easily be changed without affecting the program that uses it.

The advantages of abstraction are the hiding of implementation details, component reuse, extensibility, and testability. When the implementation details are hidden, a cleaner, more comprehensible, and usable interface is revealed to users. In abstracting by separating an interface from the implementation one can makes component reuse more practical.

One of the most commonly used abstract data types in BASIC, FORTRAN, and C is the array. Struct or structure is another Abstract data type in C. There are two types of abstraction:

1. Procedural Abstraction: It uses functions and procedures of OOPs as well as user-defined or library functions to perform certain tasks in a program. Actually, the use of these functions conceals unnecessary details and the programmer need not know the precise steps performed by the function.
2. Data Abstraction: All high-level languages use data abstraction. Data Abstraction is a fundamental feature of object-oriented programming. Actually, data Abstraction is the process of defining user types and using these types only through a set of interface operations instead of directly manipulating their representations. Data Abstraction results in the formation of user-defined data types like class, int, long, float, double, and other user-defined data. The data abstraction in OOPS is much higher than in traditional language.

### > Binding

Binding is the process that is used to link some function to the code of the function at the time of calling a function. It is of two types early or static binding and late or dynamic binding. In function overloading, overloaded functions are called by matching the signature of the function, by type of the function, and the number of arguments in the function. The signature of each overloaded function should be different irrespective of the return value. The compiler on the basis of the overloaded function is able to select the appropriate function at compile time which is called early or static binding.

In operator overloading, the same operator is used for different purposes. The operator overloading makes the statements more transparent and close to real-life situations. The virtual class is used to achieve run-time polymorphism. When a derived class inherits two functions of the same name from two different base classes, an ambiguity arises as two copies of the same function are available. A virtual class ensures that only one copy of the function is available. Polymorphism plays an important role in allowing objects having a different internal structure to share the same external interface. Polymorphism is extensively used in implementing inheritance.

### > Dynamic Binding

Binding means linking. It is the linking of a procedure call to the code to be executed in response to the call. It is a connectivity of two or more two objects via an interface and creates common objects which have the linkage of all those objects.

Mainly in C++ binding are of two types, one is early binding or static binding and the second one is Dynamic binding. Dynamic Binding is also called late Binding. Late binding refers to the run-time determination of the addresses of the function to be executed in the program. In Dynamic Binding, a non-constant pointer is used to postpone the allocation of memory until the program is running. Dynamic binding means the code associated with a given procedure call is known at the time of execution. It is associated with Polymorphism and inheritance.

Difference between static binding and Dynamic binding:

 Static Binding Dynamic Binding 1. In Static Binding, the code associated with the given procedure is known at the time of compilation. 1. In Dynamic Binding, the code associated with a given procedure is known at the time of the program run. 2. Program execution is fast and efficient. 2. Program execution is a little slow. 3. Program flexibility is less. 3. Program flexibility is more. 4. It is less reliable. 4. It is more reliable. 5. It occurs externally. 5. It occurs internally.

### > Message Passing

Message passing is a method by which an object sends data to another object or requests other objects to invoke the method. This is also known as interfacing. It acts like a messenger from one object to another object to convey specific instructions.

Definition (Message):

A message is a request to an object to invoke one of its methods. A message therefore contains

• the name of the method and
• the arguments of the method.

Consequently, the invocation of a method is just a reaction caused by the receipt of a message. This is only possible if the method is actually known to an object.

Definition (Method):

A method is associated with a class. An object invokes a method as a reaction to the receipt of a message.

A method is an approach that passes the message from one location to another to call the required procedure. Different types of programming follow different methods to enhance the programming level. In OOPS, the concept of the method is directly linked with the message passing and reusability of the applications.

A message for an object is a request for the execution of a procedure. It will call a function or procedure in the receiving object that generates the desired result. Message passing involves specifying the name of the object, the name of the function, and the information to be sent.

### > Reusability:

The object-oriented technique is built from some reusable software area. It saves programming effort making the programs more transparent and easy to understand. Once a class has been written, created, and debugged, it can be distributed to other programmers for use in their own programs. This is called reusability. Once a class has been written and tested, it can be adapted by another programmer to suit their requirements. This is basically done by creating new classes, and reusing the properties of the existing ones that explain the concept of Reusability.

Reusability in general is a requirement of the code base you’re working on. It comes with costs. Examples of such code bases are libraries, frameworks, and central components in a large company. So, you should ask yourself if it really needs to be reusable and to what extent. If there’s no way around it, you better have a profound understanding of others’ requirements in order to keep the development costs low.

Actually, reusability is not an OOP term, it is about reusing existing code to solve problems used in software engineering. This way you don’t have to write the same thing twice. Writing the same code twice obviously means that you will spend more time writing code, but it has another disadvantage. If you want to modify the code, for example, fix a bug in the algorithm or extend it with a new parameter, then you have to modify it in two or more different locations. Which means even more typing, and more opportunities to add new bugs to the code. So reusability is a must if a maintainable code. you want

Reusability is when a class inherits or derives another class, it can access all the functionality of the inherited class. Similarly, student report cards and class schedule objects can be reused by different tables in the student registration projects. It can be represented as shown in the above figure.

Definition:

Reusability is the ability of an item that allows it to be used repeatedly unlike a disposable item.

Following are the some major advantages of reusability of the object-oriented code:

• By using the concept of reusability, programs are implemented more efficiently using less memory and code. It is similar to the way a library of functions in a procedure language can be incorporated into different programs.
• The programmer is able to add some new features or to change the existing codes, and thus the new classes can be derived from existing ones. So programmers can devote time to writing new code instead of wasting time rewriting the existing code.
• Programming errors become isolated within the new code-derived classes. As it uses the concept of inheritance, the subclass can inherit the functionality of the base class. Since the code of the base class is already debugged and in operation, inheritance of code from the base class will support reusability which will save time and effort.
• It also reduces the coding of the program.

So a reusable component saves effort because it does not need to be redesigned, recorded, and retested for every application. A reusable component is also likely to be more reliable than a component that is used only once. For example, suppose a computerized game has been developed by using the OOPS concept. Now if some new features are to be added to the game then to do this, simply a new class is created that inherits all the capabilities of the existing one. Also, some new portions can be added to it. So it is a major benefit to OOPs.

Reusability is derived from the concept of inheritance. So a programmer can take an existing class and without modifying it, add features to it.

There are few things one can do to make functions more reusable–passing data as arguments rather than assuming specifically-named global variables, The reusability is inherently limited in at least three ways:

• Function names are global variables; each function must have a unique name. This makes it difficult to rely heavily on library code when building a complex system. Classes, on the other hand, can share programming interfaces. When the same naming conventions are used over and over again, a great deal of functionality can be packaged with a relatively small and easy-to-understand interface.
• Functions are selected from a library one at a time. It’s up to programmers to pick and choose the individual functions they need. In contrast, objects come as packages of functionality, not as individual methods and instance variables. They provide integrated services, so users of an object-oriented library won’t get bogged down piecing together their own solutions to a problem.
• Functions are typically tied to particular kinds of data structures devised for a specific program. The interaction between data and function is an unavoidable part of the interface. A function is useful only to those who agree to use the same kind of data structures it accepts as arguments. Because it hides its data, an object doesn’t have this problem. This is one of the principal reasons why classes can be reused more easily than functions.

### > Modularity

Modularity is decomposing a large (or even not-so-large) program into different files or manageable pieces. Each piece works independently and is compiled alone, then integrated with other pieces when the program is linked.

Definition:

It is the property of a system that has been decomposed into a set of cohesive and loosely coupled modules.

Using the static storage class designator to limit the scope of names to just the files where they’re declared enhances the independence of source modules. This kind of module is a unit defined by the file system. It’s a container for source code, not a logical unit of the language. Memory is allocated for the instance variables of each new object, but there’s no need to allocate memory for methods. All an instance needs are access to its methods and all instances of the same class share access to the same set of methods. There’s only one copy of the methods in memory, no matter how many instances of the class are created.

The main advantage of modularity is reusability. By dividing a complex problem into modules and implementing them differently, reusability can be achieved as these modules can be used when the need for the same task arises in a similar problem. Also, of course, modularity increases code legibility and it is an efficient way of handling difficult and lengthy tasks by dividing each module’s responsibility amongst various developers.

Always remember:

1. OOP languages combine data and functions into a single unit called an object.
2. All Object-oriented programming languages have three concepts in common: object, Polymorphism, and Inheritance.
3. An object is said to represent a class and its features.
4. The return type of function does not contribute to function overloading.
5. Encapsulation gives the more clear results and is more powerful than conventional languages that separate data structure and its behavior.
6. All traditional languages support abstraction while object-oriented languages support a very powerful abstraction with ADT (Abstract data type).
7. Reusability reduces code and not the size of the program.
WRITTEN BY

## xalgord

Highly motivated, Hard-working, and Resourceful Programmer. I Love To Explain And Teach Technology, Solve Tech Problems And Learn Something New Every Day.