01-Introduction To OOP
01-Introduction To OOP
01: Introduction
Semester I, 2022
Procedural Programming
Traditional programming languages were procedural.
C, Pascal, BASIC, Ada and COBOL
2
Procedural Programming
Data Element
Function A Function B
3
Object Oriented Programming
Object-oriented programming (OOP) is a currently
popular and powerful programming technique.
5
Object-Oriented Programming
Object
Attributes (data)
Methods
(behaviors / procedures / functions)
6
Object-Oriented Programming
Object-oriented programming combines data and methods
via encapsulation.
7
Object-Oriented Programming
Object
Attributes
Programming typically private to this object
Interface
Other
Other
objects
Other
objects
objects
Methods
8
Object-Oriented Programming Languages
Pure OO Languages
Smalltalk, Eiffel, Actor, Java
Hybrid OO Languages
C++, Objective-C, Object-Pascal
9
Classes
10
Objects
Classes can be used to instantiate as many objects as are
needed.
11
Classes and Objects
The Car class defines the
attributes and methods that will Corolla object
exist in all objects that are
The Corolla object is an
instances of the class. instance of the Car class.
Car class
The Santa Fe object is an
instance of the Car class.
Santa Fe object
12
GENERAL CONCEPTS OF OOP
1. DATA ABSTRACTION
2. DATA ENCAPSULATION
3.MODULARITY
4. INHERITANCE
5.POLYMORPHISM
13
Data Abstraction
١٤
Encapsulation
Encapsulation is a key concept in working with objects:
Combining attributes and methods in one package and
hiding the implementation of the data from the user of the
object.
Example:
a car has attributes and methods below.
Car
Encapsulation: Attributes:
model,
cylinder capacity
Attributes/data DATA
+ MEMBER
FUNCTIONS Methods:
Methods/functions = Class move,
accelerate
DATA
DATA
MEMBER
FUNCTIONS MEMBER
FUNCTIONS
Data Abstraction & Encapsulation 15
Data Hiding
Data hiding ensures methods should not directly access instance
attributes in a class other than their own.
Programs should interact with object attributes only through the object's
methods.
16
Modularity
١٧
Associations
Association: relates classes to each other through their objects.
Association can be, one to one, one to many, many to one, or many to
many relationships.
Example:
A person can own several cars
Person Car
owns 0..*
Works for
Company
18
Inheritance
Inheritance is the ability of one class to extend the capabilities of
another.
it allows code defined in one class to be reused in other classes
Example:
Car and Truck are Car Truck Car and Truck are
Specialized versions of child classes of
a Vehicle. Vehicle.
19
Polymorphism
Example:
Insects have the ability to
move from one point to
another.
Insect
20
The Unified Modeling Language
The Unified Modeling Language
22
UML Class Diagram
23
Example: A Rectangle Class
A UML diagram for a class has three main sections.
24
UML Access Specification Notation
In UML you indicate a private member with a minus (-)
and a public member with a plus(+).
25
UML Data Type Notation
26
UML Parameter Type Notation
27
UML Function Return Type Notation
28
The Rectangle Class
29
Showing Constructors and Destructors
30