CH 11 OOP

Download as pdf or txt
Download as pdf or txt
You are on page 1of 9

Introduction to Object Oriented Programming

The term Object Oriented Programming is a relatively new concept in the world of
programming languages. Earlier the only style of programming was known as
Sequential or Linear or Procedural Programming. Every program has two parts: Code
and Data. The code part consists of the statements that are executed to perform the
job. The data part consists of the variables which hold the necessary values to
perform the job. In Sequential programming style more emphasis is placed on the
code part and less on the data part. The code statements are executed one by one,
sequentially, meaning that you can execute statement number n if you have already
executed statement number n-1, and the next statement to execute is statement
number n + 1.

In Object Oriented Programming, the style is changed. Basically, more emphasis is


placed on the data part and emphasis placed on the code part is secondary. Everything
you have to consider must be viewed as an object. The definition of an object is like
the following.
An object is a collection of a set of data and a set of code. The data part is called
attributes (formed as variables) and the code part is called functions (formed as
executable statements). The relationship between the attributes and the functions is
such that if a function is executed, the values of some attribute can be accessed or
changed. In other words, to access or change the value of some attribute, we must
execute the proper function.

Let us explain with an example. Consider ‘chair’ to be an object. We can say that any
chair in the world must have a set of attributes like height, width, breadth, color,
material, weight, price and location. To validate our case, we illustrate three different
chairs of different types.

1
The attribute set described above defines the data part of the three chair objects. You
can see that all the three chairs have the identical attribute set. It may happen that the
value within the individual attribute could be different for the three objects. For
example the three objects have different values for the material attribute, but all of
them have the material attribute in their set of attributes.

But as they are objects, the chairs must also have a set of functions (meaning what we
can do with these chairs). The set of functions could be like the following:
Buy();
Sell();
Repair();
Paint();
Move();
As you can understand, if we execute these functions, then one or some of the
attribute values will be accessed or changed. For example, to Buy() or Sell()
the chair, its price attribute will be changed. To Repair() a chair, we may change
its dimensions, weight or material. To Paint() a chair its color property will be
changed. To Move() a chair, we change its location.

The concept of Class


If some objects are found to have a similar set of attributes and a similar set of
functions, then these objects can be grouped together into a class. A class is a
collection of declaration of the attribute variables and the definition of the functions.
Once the class has been defined, we can create as many objects of a class as we need
just as we declare variables of a data type. In the light of a class, an object can also be
defined as an instance or occurrence of a class.

We may declare the CHAIR class as having declared variables like height, width,
breadth, color, material, weight, price and location and define the functions like
Buy(), Sell(), Repair(), Paint() and Move(). Now, in order to declare a
new object Chair4, all we need to do is write the following statement:

CHAIR Chair4; (Equivalent to int n;)

And the job is done.

Each object has its own space in memory where it can store its own attribute set,
because each object is expected to have a unique attribute set of its own. However,
there is no need to store separate copies of the functions for each individual objects,
as the coding for the functions need not be changed for each object.

Writing the actual program in an object oriented system is fairly easy. All we have to
do is to execute the appropriate function with the appropriate object. For example, if
we want to sell Chair2, then we may write:
Chair2.Sell();
2
And if we want to move Chair3 then we may write:
Chair3.Move();

Feature/ Characteristics of OOP:


The basic concepts underlying OOP are: Class, Object, abstraction,
encapsulation, inheritance, and polymorphism.

1. Class: Class is a collection of objects. It is like a blueprint for an object. In the


C++ programming language, a class is the foundational element of object-
oriented programming. An instance of a class is created for accessing its data
types and member functions.

3
2. Object: An object is a real-world entity that has a particular behavior and a
state. It can be physical or logical in C++ programming language. An object is
an instance of a class and memory is allocated only when an object of the
class is created.

3. Inheritance: It is the phenomenon when a class derives its characteristics


from another class. In other words, when an object of a class derives all its
properties from the parent object. The class that inherits the properties is
known as the child class/derived class and the main class is called
the parent class/base class.

4
4. Polymorphism : Polymorphism means the ability to take more than one form
in the C++ programming language. With this feature, you can use the same
function to perform different tasks thus increasing code reusability. It
includes function overloading and operator overloading.

5
5. Encapsulation & Abstraction: Encapsulation is the wrapping up of the
functions and data together in a single unit. By privatizing the scope of the
data members it can be achieved. This particular feature makes the program
inaccessible to the outside class.
Abstraction in C++ programming language helps in the process of data hiding. It
assists the program in showing the essential features without showing the
functionality or the details of the program to its users. It generally avoids

6
unwanted information or irrelevant details but shows the important part of the
program.

Difference between Procedure Oriented and OOP

7
Overview of other High Level Programming Languages
1. Python: Known for its readability and versatility, Python is often used in web
development, data analysis, arti cial intelligence, scienti c computing, and
automation. Its syntax is clean and straightforward, making it a popular choice for
beginners.

2. Java: Java is widely used in enterprise applications, Android app development, and
large-scale systems. It’s known for its platform independence (write once, run
anywhere), object-oriented programming features, and strong community support.

3. JavaScript: Primarily used for web development, JavaScript allows for interactive
and dynamic websites. With frameworks like React, Angular, and Vue.js, JavaScript
is also used for building complex front-end applications.

4. C#: Developed by Microsoft, C# is commonly used for building Windows


applications, web applications with ASP.NET, and games using Unity. It’s known for
its strong typing, scalability, and integration with the .NET framework.

5. Ruby: Known for its elegant syntax and focus on developer happiness, Ruby is
commonly used in web development with frameworks like Ruby on Rails. It
prioritizes simplicity and productivity, making it a favorite among startups.

6. PHP: Widely used for server-side scripting, PHP powers many dynamic websites
and web applications. It’s known for its integration with databases like MySQL and is
often used in content management systems like WordPress.

7. Swift: Developed by Apple, Swift is used for building iOS, macOS, watchOS, and
tvOS applications. It’s designed to be safe, fast, and modern, with features like
optionals, type inference, and memory management improvements.

8. Go (Golang): Created by Google, Go is known for its simplicity, ef ciency, and


concurrency support. It’s used in backend development, cloud services, and
8
fi
fi
fi
distributed systems due to its strong performance and built-in support for
concurrency.

9. R: Speci cally designed for statistical computing and data analysis, R is used by
data scientists, statisticians, and researchers. It has extensive libraries for data
manipulation, visualization, and machine learning.

These languages cater to different domains and have their strengths and weaknesses,
so the choice of language often depends on the speci c requirements of a project.

9
fi
fi

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy