The Concepts Behind Object Oriented Programming Computer Science Essay

Published:

This essay has been submitted by a student. This is not an example of the work written by our professional essay writers.

Object Oriented Programming (OOP), is a term used to describe an application that is composed of multiple objects connected to each other. Programming languages were simply a group of functions or instructions earlier. Using the concept of OOP, every object can handle data and perform other actions. The objects will all act as independent units possessing their own actions and will be responsible for carrying out processes. The objects are not dependent on each other and hence Object Oriented Programming is more flexible than older programming methods.

Programming Patterns and Techniques

Here, we shall be discussing the programming techniques which are in general categorised as follow:

Unstructured programming

Procedural programming

Modular programming

Object Oriented Programming

Let us now see what these mean in a programming language.

Unstructured Programming

Beginners start programming by writing simple programs which contain only of a main() function, where main acts as a sequence of commands or compound statements which modify data throughout the program. The following figure shows the outline.

Program

main() function

{ commands }

The unstructured programming technique proves disadvantageous once the program becomes huge.

Procedural Programming

This pattern enables us to combine returning sequences into a single place. A procedure initiates the procedure. After the sequence is processed, the flow of control moves right after the position from where its the main program procedure.

Main

Procedure

End

Procedures get executed after processing flow of controls proceeds where it was called from. Including parameters as well as procedures of procedures (known as sub-procedures) programs can be written in structured way making them less prone to errors. The program can be viewed as a sequence of procedure calls. The main() function is responsible to send data to the individual needs and the data is processed by the procedures where the resulting data is presented.

main()

procedure1 procedure2 procedure3

The main program coordinates connections to the procedures and sends appropriate data to it. Overall result of this is, we have a single program which is sectioned into different pieces named as procedures_ To enable usage of general procedures or groups of procedures. But what if too many procedures pile up? For that reason, we have modular programming which allows grouping of procedures into modules as given below.

Modular Programming

Using modular programming, procedures with similar/common functionalities are grouped together into modules defined for each group. This makes the program contain more number of parts and hence its divided into small sections making it easy to interact. Also the whole program is made by blocks of codes

main()

Module 1 Module 2

Procedures Procedures

The main program calls the procedures in separate modules and hands over appropriate data as parameters. Each module can have its unique data. This allows each module to possess an internal state which is modified by calls to procedures of the particular module, although there is only one state per module and each module exists at most once in the whole program.

Object Oriented Programming

Object Oriented Programming (OOP) is the advanced technique which overcomes the disadvantages of the other programming patterns and also propagate their advantageous features. The below illustration show how OOP handles a program

Object B

{ Data }

Object C

{ Data }

Object A

{ Data }Program

We have a web of interacting objects inside a single program, which means that any object can interoperate with any other object during execution which is in contrast with the other patterns we saw earlier

Objects of the program interact by sending data to each other. Consider the multiple lists to be handled. The problem here with modular programming is that we should explicitly create and destroy your list handlers. Then we use the procedures of the module to modify each handle. Unlike OOP, we would have as many list objects as needed. Instead of calling a procedure which we must provide with the correct list handle, we would directly send a message to the list object in question. Roughly speaking, each object implements its own module and is responsible to initialize and destroy itself. There no longer exists the need to explicitly call a creation or termination of a procedure.

ABSTRACT DATA TYPE

In this section let us see abstract data types as a basic concept for implementing Object Oriented Programming

Let us take an example to explain this. Consider a car manufacturing factory holding the records on car assemblies. Each car has its own unique features. Each of these features are recorded in a file with the following details.

Name of Part:

Property:

Integral Role:

Not all of these properties are necessary to solve the problems which arise while dealing with the parts. Consequently we create a model of an parts of cars for the problem. This model only implies properties which are needed for the requirements of the repair.

Abstract Data Types

The example above shows that with abstraction we create a defined entity which can be handled. The data structure can only be accessed with defined tasks. This set of operations is called interface and is exported by the entity. An entity with the

properties just described is called an abstract data type.

Properties of Abstract Data types

Export type of value.

Export a set of operations called as interface.

Operations of the interface are the one and only access mechanism to the data structure

Axioms and preconditions define the application domain of the type

General Abstract Data Types

They are used to define a new type from which instances can be created. Here, only the type of the data elements change according to what type the list should operate on. This additional information could be specified by a generic or general parameter which is specified during instance creation. Thus an instance of a generic ADT is actually an instance of a particular variant of the according ADT

Notation

As abstract data types provide an abstract view to describe properties of sets of entities, their use is independent from a particular language. Hence we introduce a notation here as follows

Data: This part describes the structure of the data used in the abstract data type in an informal way.

Operations: This part describes valid operations for the data type. It describes its interface and a special operation constructor is used to describe the actions which are to be performed once an entity is created and destructor to describe the actions which are to be performed once an entity is destroyed. For each operation the provided arguments as well as pre-conditions and post-conditions.

Abstract Data Types and OOP

Abstract data types allow the creation of instances with well-defined properties and behaviour. In OOP, these are referred to as classes. Hence a class defines properties of objects which are the instances an environment.

They become functional by referencing the involved data, their structure and their operations as axioms and pre-conditions. Consequently OOP is programming with these data types combining functionality of different data types to solve problems. Therefore instances objects of these data types' classes are dynamically created and destroyed

Features of Object Oriented Programming

We already discussed in the previous sections about some Object Oriented Programming concepts. Let us now walk through these concepts in detail.

Implementation of Abstract Data Types

It continues with the discussion about Abstract data type as an abstract view to define properties of a set of entities. Object Oriented Programming languages must allow implementation of these types. Subsequently, once it is implemented, we have a specific representation for it.

Programming languages such as Pascal, C and others already offer an implementation for it. Once we create a variable of this type, we can use its provided operations.

OOP is characterised by its major features as follow:

Classes

Objects

Inheritance

Data Abstraction

Data Encapsulation

Polymorphism

Overloading

Reusability

Let us first see a summary of each of these before proceeding to explanation and examples.

FEATURES OF OBJECT ORIENTED PROGRAMMING IN BRIEF

Inheritance:

It is the process of forming a new class from an existing class or base class (which is also known as parent or super class). The hence newly formed class is called the derived class (also known as child class or sub class). Inheritance helps in reducing the overall code size of the program, which is an important concept in object-oriented programming.

Data Abstraction:

Data Abstraction helps in creating user defined data types and hence increasing the depth in reach for user. It represents the needed information in the program without showing the unnecessary details.

Data Encapsulation:

Encapsulation combines or encapsulates data and functions into a single unit which we'll later refer to as Class. When using Data Encapsulation, data is not accessed directly and is only accessible through the functions present inside the class. It enables the possibility of data hiding which comes in handy while programming.

Polymorphism:

Polymorphism allows routines to use variables of different types at various times. An operator or function can be given different meanings or properties. Polymorphism refers to a single function or multi-functioning operator performing in different ways. It can be briefed as enabling multiple faces.

Overloading:

Overloading falls under the category of polymorphism too. It allows an object to have different meanings, depending on its context. When an existing operator or function begins to operate on new data type, it is being overloaded.

Reusability:

This term refers to the ability for multiple programmers to use the same written and existing class of data. It saves time and adds program code efficiency to the language. Also, the programmer can add in new features to the existing class, hence further developing the application and allowing users to achieve increased performance. This feature optimizes code, helps in gaining secured applications and facilitates easier maintenance on the application.

Objects:

Object is the basic unit of OOP. Objects are identified by an exclusive name. They represent a particular instance of a class and there can be more than one instance of an object. Each instance of an object can hold its own relevant data. An Object is a collection of data members and associated member functions (methods).

Classes:

Classes are data types based on which objects are created. Objects with similar properties and methods are grouped together in them. A Class represent a set of individual objects and the characteristics of these objects are represented as Properties. Actions that can be performed by objects become functions of the class. No memory is allocated when a class is created and is done only when an instance (object) of a class is created.

Class

A class is the implementation of an abstract data type. It defines attributes and methods which implement the data structure and operations of the these data types respectively. Instances of classes are called objects. Consequently classes define properties and behaviour of the objects.

Let us see a small example for a class.

class xyz

{

int i,k; //attributes

input(int g); //method

output(); //method

};

In the example above, the notation class xyz denotes the definition for a class. Enclosed in the curly brackets are two sections namely attributes and methods which define the implementation of the data structure and operations of the corresponding abstract data type. Again we distinguish the two levels with different terms. In our example, the data structure consists of only one element, a sequence of digits. The corresponding attribute are ordinary integers of C++ and defied two methods input() and output() representing the two operations get and put.

Object

In the parts of the car example, we saw instances of abstract parts. These instances are actual examples of an abstract part and hence contain actual values to represent a particular part which are called as objects.

An object is an instance of a class. Objects are exclusively identified by a name for then. We hence can have two different objects with the same set of values too. This is similar to traditional usage where we may have two integers j and k both of which can have same values. We refer to the set of values at a particular time as the state of the object. The state of the object changes according to the methods which are applied to it. We refer to these possible sequences of state changes as the object behaviour. The behaviour of an object is defined by the set of methods which can be applied on it.

Abstraction

The concept of abstraction shares the idea of hiding data that are not needed for the end-user. The idea behind data abstraction is to give a clear separation between properties of data type and the associated implementation details. This separation is achieved in order that the properties of the abstract data type are visible to the user interface and the implementation details are hidden. Hence, abstraction forms the basic platform for the creation of user-defined data types called objects. Data abstraction is the process of refining data to its essential form. An Abstract Data Type is defined as a data type that is defined in terms of the operations that it supports and not in terms of its structure or implementation. 

In C++, as it is an OOP language, it is possible to create and provide an interface that accesses only certain elements of data types. The programmer can decide which user to give or grant access to and hide the other details. This concept is called data hiding which is similar in concept to data abstraction.

Types of Abstraction

There are two basic types as follows

Functional abstraction

Data abstraction.

The main difference between functional abstraction and data abstraction is that former refers to a function that can be used without taking into account how the function is implemented. Data abstraction refers to the data that can be used without taking into account how the data are stored. There is also a difference in the way the access takes place in functional abstraction and data abstraction. In functional abstraction, access to the function is provided through a specific interface defined to invoke the function. In contrast, in data abstraction, access to the data is provided through a specific set of operations defined to examine and manipulate the data. For instance, when a programmer is using C++ standard data types, this means that users are using the concept of data abstraction. When using data types, the users are not concerned with how the data is stored but they are concerned with what operations are provided and what properties are supported.

Need of Abstraction

Flexibility in approach

Enhanced Security

Easier Replacement

Modular Approach

There are various ways of achieving abstraction in object-oriented programming language C++. One approach is to take modular based code that is broken apart into smaller segments, known as functions. This functional or modular approach helps the code to be reused again and again when needed. For example, a programmer might write a function for computing an average and another programmer might write a function for computing salary. These functions can be reused when needed.

Encapsulation

It is the process of combining data and functions into a single unit which we named as class. Using encapsulation, we cannot directly access the data. Data is only accessible through the functions which are inside the class. Data encapsulation led to the important concept of data hiding. Data hiding is the implementation details of a class that are hidden from the end-user. The concept of restricted access directed programmers to write specialized functions or methods for performing the operations on hidden members of the class.

Hiding the implementation details and providing restrictive access leads to the concept of abstract data type. Encapsulation leads to the concept of data hiding, but the concept of encapsulation must not be restricted to information hiding. Encapsulation clearly represents the ability to bundle related data and functionality within a single, autonomous entity called a class. Let us consider the following example.

class xyz

{

public:

int input(int r);

int add();

int output();

private:

int a;

float b;

};

In the above example, the data members including integer x and float b, and member functions input(), add() and output() are bundled and put inside a single autonomous entity called class xyz. This demonstrates the concept of Encapsulation. There are advantages of using this encapsulated approach in C++. One advantage is that it reduces human errors. The data and functions bundled inside the class take total control of maintenance and thus human errors are reduced. It is clear from the above example that the encapsulated objects act as a black box for other parts of the program through interaction. Although encapsulated objects provide functionality, the calling objects will not know the implementation details. This enhances the security of the application.

The key strength behind Data Encapsulation in C++ is that the keywords or the access specifiers can be placed in the class declaration as public, protected or private. A class placed after the keyword public is accessible to all the users of the class. The elements placed after the keyword private are accessible only to the methods of the class. In between the public and the private access specifiers, there exists the protected access specifier. Elements placed after the keyword protected are accessible only to the methods of the class or classes derived from that class.

The concept of encapsulation shows that a non-member function cannot access an object's private or protected data. This adds security, but in some cases the programmer might require an unrelated function to operate on an object of two different classes. We then are able to utilize the concept of friend functions. Encapsulation alone is a powerful feature that leads to information hiding, abstract data type and friend functions.

Features of Encapsulation:

Makes Maintenance of Application Easier

Improves the understanding of the Application

Enhanced Security

There are numerous reasons for the enhancement of security using the concept of Encapsulation in C++. The access specifier acts as the key strength behind the concept of security and provides access to members of class as needed by users. This prevents unauthorized access. If an application needs to be extended or customized in later stages of development, the task of adding new functions becomes easier without breaking existing code or applications.

Inheritance

Inheritance is the process by which new classes called derived classes are created from existing classes called base classes. The derived classes have all the features of the base class and the programmer can choose to add new features specific to the newly created derived class.

For example, a programmer can create a base class named cars and define derived classes as tires, body kits, engine, etc. Each of these derived classes, (tires, body kits, and engine) has all the features of the base class (cars) with additional attributes or features specific to these newly created derived classes. This concept of Inheritance leads to the concept of polymorphism.

Features or Advantages of Inheritance

Reusability

Saves Time and Effort

Increases Program Structure which results in greater reliability.

Polymorphism

For example, if the base class is cars and the derived class is manufacture, it is specified as:

class manufacture: public cars

Inheritance Example:

class cars

{

public:

cars();

void abc(int k);

void output(void) { cout<<x; }

private:

int x;

};

class manufacture: public cars

{

public:

sample();

void f1(int n);

private:

int s1;

};

Polymorphism

It is the ability to use an operator or function in different ways. Polymorphism gives different meanings or functions to the operators or functions. Poly, referring to many, signifies the many uses of these operators and functions. A single function usage or an operator functioning in many ways can be called polymorphism. Polymorphism refers to codes, operations or objects that behave differently in different contexts.

A simple example of the above concept of polymorphism:

1 + 2 : Integer Addition

The same + operator can be used with different meanings.

"abc" + "xyz" : String concatenation

7.15 + 3.78 : Float addition

Polymorphism is a Strong feature of the OOP. A single operator + behaves differently in different contexts such as integer, float or strings referring the concept of polymorphism. The above concept leads to operator overloading. The concept of overloading is also a branch of polymorphism. When the exiting operator or function operates on new data type it is overloaded. This feature of polymorphism leads to the concept of virtual methods.

Polymorphism refers to the ability to call different functions by using only one type of function call. Suppose a programmer wants to code vehicles of different shapes such as circles, squares, rectangles, etc. One way to define each of these classes is to have a member function for each that makes vehicles of each shape. Another convenient approach the programmer can take is to define a base class named Shape and then create an instance of that class. The programmer can have array that hold pointers to all different objects of the vehicle followed by a simple loop structure to make the vehicle, as per the shape desired, by inserting pointers into the defined array. This approach leads to different functions executed by the same function call. Polymorphism is used to give different meanings to the same concept. This is the basis for Virtual function implementation. C++ provides three different types of polymorphism

Types of Polymorphism

Virtual functions

Function name overloading

Operator overloading

Features of Polymorphism

Helps in reusability of code.

Provides easier maintenance of applications.

Helps in achieving robustness in applications.

Types of Polymorphism:

ABSTRACT CLASS

With inheritance we are able to force a subclass to offer the same properties like their super-classes. Consequently, objects of a subclass behave like objects of their super-classes.

Sometimes it makes sense to only describe the properties of a set of objects without knowing the actual behaviour beforehand. Let us consider the following example

abstract class xyz

{

int a; //attributes

input(); //methods

}

We introduce the keyword: abstract. It is used to express the fact that derived classes must redefine the properties to satisfy the desired functionality. Hence from the abstract class point of view, the properties are only specified but not fully defined. The full definition including the semantics of the properties must be provided by derived classes.

A class xyz is called abstract class if it is only used as a superclass.

Class xyz only specifies properties and it is not used to create objects.

Derived classes must define the properties of xyz.

Abstract classes allow us to structure our inheritance graph.

Summary

A method is same as function, but the typical OO notation is used for the call. F(x,y) is written x.F(y) where x is an object of class that contains this f method.

Sending a message is calling a function (method).

Instantiating is allocation a class/struct object (instance) with the "new" keyword.

A class is simply a struct with both data and functions, with OOP features.

Object is an instance or a memory allocated to a class/struct. An object is like a carbon copy of the class in a usable form.

Members are fields or functions of a class if defined inside that class.

Constructor is a function-like code that initializes new objects (instances) when they instantiated.

Destructor is another function-like code that is called when an object is deleted to free any resources (memory) that has pointers to.

Inheritance is defining a class (child) in terms of another class (parent). All of the public members of the public class are available in the child class.

Polymorphism is defining functions with the same name, but different parameters.

Encapsulation is combining data into modules.

A function is overloaded if there is more than one definition.

Redefine a function from a parent class in a child class is called overriding.

A subclass is the same as child, derived, or inherited class.

A superclass is the same as parent or base class.

An attribute is same as data member or member field.

Unstructured programming pattern contains all the codes in the same function and proves to be inefficient when it comes to clarity and ease of debugging.

Procedural programming is slightly more efficient as it contains procedures (functions) as a part of the program which makes it easier to debug.

Modular programming is a slightly higher level programming as the program is split into many modules.

Object oriented programming is the highest efficiency programming as it handles data in form of classes and objects which make better and efficient use of resources and clarity of program is good along with easy debugging.

Using Abstract data types we create a defined entity which can be handled. The data structure can only be accessed with defined tasks.

Abstraction is of types functional and data abstraction.

Code reusability is the concept where an existing set of program codes are reused instead of repeating them again.

Abstract class is that derived classes must redefine the properties to satisfy the desired functionality.

Test Yourself Quiz

What is abstraction?

How is polymorphism implemented?

What are the advantages of OOP?

What is overloading?

What is a method?

What are the different programming paradigms?

What is modular programming?

What are constructors and destructors?

What is overriding?

What is code reusability?

Writing Services

Essay Writing
Service

Find out how the very best essay writing service can help you accomplish more and achieve higher marks today.

Assignment Writing Service

From complicated assignments to tricky tasks, our experts can tackle virtually any question thrown at them.

Dissertation Writing Service

A dissertation (also known as a thesis or research project) is probably the most important piece of work for any student! From full dissertations to individual chapters, we’re on hand to support you.

Coursework Writing Service

Our expert qualified writers can help you get your coursework right first time, every time.

Dissertation Proposal Service

The first step to completing a dissertation is to create a proposal that talks about what you wish to do. Our experts can design suitable methodologies - perfect to help you get started with a dissertation.

Report Writing
Service

Reports for any audience. Perfectly structured, professionally written, and tailored to suit your exact requirements.

Essay Skeleton Answer Service

If you’re just looking for some help to get started on an essay, our outline service provides you with a perfect essay plan.

Marking & Proofreading Service

Not sure if your work is hitting the mark? Struggling to get feedback from your lecturer? Our premium marking service was created just for you - get the feedback you deserve now.

Exam Revision
Service

Exams can be one of the most stressful experiences you’ll ever have! Revision is key, and we’re here to help. With custom created revision notes and exam answers, you’ll never feel underprepared again.