0% found this document useful (0 votes)
23 views27 pages

L14-OOP Concepts

Uploaded by

Samarth Gandhat
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
23 views27 pages

L14-OOP Concepts

Uploaded by

Samarth Gandhat
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 27

LESSON - 14

ELEMENTARY CONCEPT OF
OBJECTS AND CLASSES
STUDY OF OBJECT ORIENTED PROGRAMMING
DEFINITION

Object Oriented means


directed towards objects This
model compartmentalizes
data into objects (data fields)
and describes object contents
and behavior through the
declaration of classes
(methods).
DIFFERENCE BETWEEN PROCEDURAL LANGUAGE AND OOP
Procedural Programming Object Oriented Programming

It focuses on the process and functions. It focuses on the data and classes.

If a sub-procedure has to be modified, it It is easy to maintain code and modify existing


becomes difficult to find and maintain it. code.

Due to its complexity, development time Due to easy maintenance, development time
increases. reduces.

Procedural programming languages are not as The object-oriented programming languages are
faster as object-oriented. faster and more effective.

Designs cannot be reused and recycled Designs can be reused throughout the program.
throughout the program.
FEATURES OF OBJECT ORIENTED PROGRAMMING
➢ Object oriented programming (OOP) uses modular
approach in programming.

➢ OOP approach provides advantages in creation and


development of software for real life application.

➢ The basic element of object oriented programming is


the data.

➢ The programs are built by combining data and


functions that operate on the data.

➢ Some of the OOP’s languages are C++, Java, C


#, and Python etc.
BASIC ELEMENTS OF OOP(PRINCIPLES OF OOP)

● Objects
● Classes
● Data Abstraction
● Encapsulation
● Inheritance
● Polymorphism
● Data Handling
CLASSES AND OBJECTS
A class is a user defined blueprint or prototype from
which objects are created. It represents the set of
properties or methods that are common to all
OBJECTS objects of one type.

• An Object is a basic unit of OOP When an object of a


class is created, the class is said to be instantiated.

• All the Objects share the attributes and the behavior


of the class. But the values of those attributes, i.e.
the state are unique for each object.

• A single class may have any number of instances i.e.


Objects.

• Objects can interact to each other and pass/Receive


information OR messages to each other.
DIFFERENCE BETWEEN REAL WORLD OBJECT AND SOFTWARE OBJECT

Real World Software


Objects Objects

Characteristics Data Members

Behaviour Functions
● Recap

• What are objects?


• States & Behaviour
• Difference between real
world object and software
object
Class

❖ A class is a group of objects which have common


properties.

❖ It is a template or blueprint from which objects are created. It


is a logical entity.

❖ It can't be physical.
A class is a which have common properties.
Difference Between Class & Object

Class Object
● It is a representation of an abstraction
only (not real). ● It is a real and unique entity
having characteristics and
● It is an object producer hence called a
behavior.
blue print or object factory.
● It is created with the help of
● It is a logical identity. ‘new’ operator, called as the
instance of Class.
● Declared with “class” keyword. ● It is physical identity.
● A class is created once. ● Declared with “new” keyword.
● Multiple objects can be created
of a class.
STEPS to Create an Object

● 1. Declaration – It uses class as a type along with an object.

● 2.Instantiation – Creating an object (Apple, Banana).

● 3. New – The keyword new is used to allocate memory


dynamically for the storage of object.
Creating an Object for the Class

● Instantiating a Class - The phrase "instantiating a class" means the same thing as
"creating an object.“
● Here, each object in Class Fruits, is having different characteristics, and some
common
behaviors.

● SYNTAX
● <classname> <objectname> = new <classname>();
● Ex- Fruits Apple = new Fruits ();
● Fruits Banana = new Fruits ();
● It means Apple/Banana is the instance/object of class Fruits.
IMPORTANT TERMS RELATED TO CLASS

• Class is an user defined data type- Primitive Data types – int,


float, char, real ,string. These are not sufficient to handle
complex Operations.

• Class is an Object Factory – Class creates similar type of


Objects.

• Object is an instance of Class - Each object possesses


characteristic an behavior defined within the class. An object
directly represent a class.
TYPES OF CLASSES

Class
Class asas Abstract
User DefinedDataData TypeType
Class as an Object Factory
Object
Each
Class
In programming,
object
asasComposite
Instance
of a class
pre
ofData
defined
ahas
Class
Type built
Class may be used to create
When
common
User
in datacan
we ofcreate
behavior
variousavarious
data
types
or functions
type
is
objects
used
with of
objects of similar types where
athe
which
such
class,
help
as
iseach
of
to
integer,
a
beclass.
object
performed
real,
Itpossesses
character,
mayon contain
the
each object of the class
characteristic
data
stringvalues.
values
etc. isofThe
used.
and
various
data
behavior
Creating
may
types vary
asuch
possesses characteristics (data
defined
from
as
class
string,
object
means
within
integer,
tocreating
the
object
float,
class.but
data
double
Since
thetypes.
etc.
an
members) and behavior (member
object
common
This
Hence is indirectly
why,
a user
operations
a class
may
represents
create
isare
saidcarried
ato
data
a be a
methods) defined within the class.
class
out
‘composite
typeonwith
iteach
is referred
thedata
object
helptype’.
to
of
which
as
a class/This
anis
Hence, class is referred to as an
‘instance
defined
is the reason
within
of a aclass’.
the
class
class.is referred
It is to
‘object factory’.
referred
as ‘user to defined
as ‘abstract
data type.’data type.
Recap
1
Sally is continuing work on her Object-Oriented Program and is
writing code for a car, truck, and bus. These items under the
class called vehicle are referred to as _____.

1.Method
2. Items
3.Attributes
4.Objects
2
1. Sally is writing some Object-Oriented Program code for a vehicle which contains
the attributes (manufacturer, color, and price), along with what she wants the
vehicle to be able to do (start, drive, and park). This is known as a _____.
1.class
2.method
3.function
4.template
3
A _____ is a procedure associated with a class
that describes an action an object is able to
perform.
1.Routine
2. Procedure
3.Functions
4.Method
ABSTRACTION

Abstraction is one of the OOP


Concepts which is an act of I do not know how mobile
phone works internally
representing essential features
but I now all its
while programming without operations.
including background details. It is
a technique of creating a new data
type that is suited for a specific
application. Overall, abstraction
helps isolate the impact of
changes made to the code so that
if something goes wrong, the
change will only affect the
variables shown and not the
outside code.

Bank Details.
ENCAPSULATION

Encapsulation refers to the


bundling of data, along with the
methods that operate on that
data, into a single unit. A class is EXAMPLE
an example of encapsulation in
computer science in that it
consists of data and methods that
have been bundled into a single
unit. Encapsulation can be used
to hide both data members and
data functions or methods
associated with an instantiated
class or object.
INHERITANCE

Inheritance the mechanism by


which one class is allowed to
inherit the features(fields and EXAMPLE
methods) of another class.
Super Class: The class whose
features are inherited is known as
superclass(or a base class or a
parent class). Sub Class: The
class that inherits the other class
is known or a child class. The
subclass can add its own fields
and methods in addition to the
superclass fields and methods.
Reusability: we can derive a new
class from the existing class by
reusing the fields and methods of
the existing class.
POLYMORPHISM

Polymorphism is the ability of an


object to take on many forms. The
most common use of
polymorphism in OOP occurs EXAMPLE
when a parent class reference is
used to refer to a child class
object. With Polymorphism, a
message is sent to multiple class
objects, and every object
responds appropriately according
to the properties of the class. It is
the ability of different objects to
respond in a unique way to the
same message.

You might also like