Analysis of Object-Oriented Programming Principles and Advantages

Verified

Added on  2023/01/09

|9
|1287
|62
Report
AI Summary
This report delves into the fundamentals of Object-Oriented Programming (OOP), outlining its core principles and their advantages. It begins with an introduction to programming and OOP, then proceeds to explain the four pillars: inheritance, abstraction, encapsulation, and polymorphism. Each principle is illustrated with examples, including code snippets, and the advantages of each are discussed. Inheritance is explained as the mechanism for acquiring properties from a parent class, while abstraction focuses on presenting essential information while hiding implementation details. Encapsulation, the bundling of data and functions, and polymorphism, the ability of data to take on many forms, are also thoroughly examined. The report concludes by summarizing the key concepts and emphasizing the importance of OOP in modern programming practices, referencing relevant academic sources.
Document Page
Fundamentals of
Programming
Table of Contents
tabler-icon-diamond-filled.svg

Paraphrase This Document

Need a fresh take? Get an instant paraphrase of this document with our AI Paraphraser
Document Page
Introduction......................................................................................................................................3
Task 1...............................................................................................................................................3
Illustrate four principles of OOP's (object oriented programming) and their advantages..........3
Conclusion.......................................................................................................................................8
References........................................................................................................................................9
Document Page
Introduction
Programming refers to step by step process related with designing as well as development
of distinct set of programs for accomplishment of peculiar computing outcome. Generally, it
implies process associated with original development of computer problem into executable
programs (Dai, 2019). This comprises of different activities like analysis, development of
understanding, generation of algorithms, their verification and many more. This report will
provide an insight into paradigms of programming which are also referred to as four pillars.
Task 1
Illustrate four principles of OOP's (object oriented programming) and their advantages.
Programming paradigms is defined as style of programming that is liable for solving
problems by usage of some kind of programming languages by utilisation of tools as well as
techniques. Object oriented programming refers to computer programming model that is liable
for organising software designs across objects or data instead of logic and functions. In this case
object refers to data field that comprises of specific behaviour and attributes. The four pillars of
programming paradigms are illustrated beneath:
Inheritance: The mechanism associated with acquisition of properties of one class along
with behaviour of parent class is referred to as inheritance (Kelly, 2019). This implies that
programmer can reuse, modify or extend behaviour and attributes of other class. Syntax of
inheritance is illustrated below:
Syntax:
class Base
{
//Body of the base class
};
class Derived : access_specifier Base
{
// Body of derived class
};
Document Page
A simple example for addition of two numbers is specified below:
#include
using namespace std;
class X
{
int a;
void geta()
{
cout << “Enter value of a: “;
cin >> a;
}
};
class Y
{
public:
int b;
void getb()
{
cout << “Enter value of b: “;
cin >> b;
}
};
class Z: public X, public Y
{
public:
void sum()
{
cout << “Sum =” << a+b;
}
};
int main()
tabler-icon-diamond-filled.svg

Paraphrase This Document

Need a fresh take? Get an instant paraphrase of this document with our AI Paraphraser
Document Page
{
Z obj1;
obj1.geta();
obj1.getb();
obj1.sum();
return 0;
}
Output: Enter value of a: 4
enter value of b: 5
sum=9
In this case, two base classes X and Y inherits class Z. Thus, class Z inherits public
members of both these classes.
Advantages:
Through this code can be reused in which code has to be defined once but can be utilised
number of times.
Time and efforts needed will be saved along with this program structure will also be
readable (MEHTRE and VERMA, 2019). It provides more flexibility and can be debugged easily.
Abstraction: It is defined as process in which only crucial information is furnished to
outside world by hiding background details. This is liable for representing required information
within the program without illustrating its other aspects.
Example:
#include <iostream>
using namespace std;
int main()
{
cout << 'Hello, how are you?” <<endl;
return 0;
}
Document Page
In this case output will be Hello, how are you?,
In this case user will not acknowledge ways in which cout will display results on the
screen. Users can only acknowledge public interface and execution of 'cout' can be altered but
without any impact on results shown.
Advantages:
Programmer need not to write low level codes and execution of class is protected from
user level bugs (Sarcar, 2020). Users can alter internal execution without creating an impact on user level-code. This
also provides re-usability of code across the classes.
Encapsulation: It refers to mechanism associated with bundling of data and functions.
This means wrapping up of functions as well as data together as a single unit.
Example:
class Rectangle
{
public:
double getVolume(void)
{
return l*b*h;
}
private:
double l;
double b;
double h;
};
Here, variable l, b and h are private which means that this can be only accessed by other
members of class Rectangle and not any other part of program. This illustrates a way to attain
encapsulation.
Advantages:
Document Page
It minimise the complexity and aids within protection of data along with this
encapsulated classes can be easily altered. Security of data can be ensured as it protects data from any kind of unauthorised users.
This can be applied within carrying out activities like finance and marketing where high
security is needed.
Polymorphism: It denotes many forms which takes place in case there exist hierarchy
within the classes and are associated via inheritance (Taher, 2019). Basically, it implies ability of
data that has to be represented or processed within more than one form.
Example:
class PlusOperator
{
int add(int a, int b)
{
return a+b;
}
double add (double a, double b)
{
return a+b;
}
String add (String c1, String c2)
{
return c1.concat(c2);
}
}
In this case method overloading is utilised to carry out polymorphism. Here, '+' operator
is utilised for carrying out two different operations i.e. addition of two variables, a and b along
with concatenation of strings c1 and c2.
Advantages:
Single variable name can be utilised for storing variables of distinct data types (like Lont,
Int, double, float, etc.)
tabler-icon-diamond-filled.svg

Paraphrase This Document

Need a fresh take? Get an instant paraphrase of this document with our AI Paraphraser
Document Page
Polymorphism will assist programmer within reusing codes which are written once,
tested as well as implemented as per requirements (Kelly, 2019). This will lead to save
time and minimise the complexities associated with rewriting same code again.
Conclusion
From above it can be concluded that, programming refers to set of instructions which are
given to a system for carrying out any peculiar task. Object oriented programming revolves
around objects rather than procedures and functions. The four major principles of OOPs or
pillars are abstraction, encapsulation, polymorphism and inheritance.
Document Page
References
Books & Journals
Dai, R., 2019. Encapsulation and Polymorphism. In Learn Java with Math (pp. 181-183).
Apress, Berkeley, CA.
Kelly, S., 2019. Introducing Object-Oriented Programming. In Python, PyGame, and Raspberry
Pi Game Development (pp. 153-170). Apress, Berkeley, CA.
MEHTRE, V.V. and VERMA, U.R., 2019. Concepts Related to Object Oriented Program OOP‟
S: Basics.
Sarcar, V., 2020. Object-Oriented Programming Concepts. In Interactive Object-Oriented
Programming in Java (pp. 3-9). Apress, Berkeley, CA.
Taher, R., 2019. Hands-On Object-Oriented Programming with C#: Build maintainable software
with reusable code using C. Packt Publishing Ltd.
chevron_up_icon
1 out of 9
circle_padding
hide_on_mobile
zoom_out_icon
[object Object]