CH 11 OOP
CH 11 OOP
CH 11 OOP
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.
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.
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:
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();
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.
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.
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.
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.
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