0% found this document useful (0 votes)
21 views30 pages

01-Introduction To OOP

Uploaded by

7omary.44
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)
21 views30 pages

01-Introduction To OOP

Uploaded by

7omary.44
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/ 30

Object-oriented Programming Course

01: Introduction

LECTURER: Dr. Mohammed Salem Bin Wahlan


Department of Information Technology
College of Applied Sciences
Seiyun University

Semester I, 2022
Procedural Programming
 Traditional programming languages were procedural.
 C, Pascal, BASIC, Ada and COBOL

 Programming in procedural languages involves choosing


data structures (appropriate ways to store data), designing
algorithms, and translating algorithm into code.

 In procedural programming, data and operations on the


data are separated.

 This methodology requires sending data to


procedure/functions

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.

 OOP involves programming using objects.


 OBJECT is an identifiable entity with some
characteristics and behavior.
 In OOP programming object represents a entity that
can store data and has its interface through functions.
 CLASS is a template representing a group of objects
that share common properties and relationships.
٤
Object-Oriented Programming
 Object-oriented programming (OOP) is centered on objects
rather than procedures / functions.

 Objects are a melding of data and procedures that


manipulate that data.

 Data in an object are known as properties or attributes .

 Procedures/functions in an object are known as methods.

5
Object-Oriented Programming
Object
Attributes (data)

Methods
(behaviors / procedures / functions)

6
Object-Oriented Programming
 Object-oriented programming combines data and methods
via encapsulation.

 Data hiding is the ability of an object to hide data from other


objects in the program

 Only object’s methods should be able to directly manipulate


its attributes

 Other objects are allowed to manipulate object’s attributes


via the object’s methods.

 This indirect access is known as a programming interface

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

 A class is the template or mould or blueprint from


which objects are actually made.

A class encapsulates the attributes and actions that


characterizes a certain type of object.

10
Objects
 Classes can be used to instantiate as many objects as are
needed.

 Each object that is created from a class is called an instance of


the class.

 A program is simply a collection of objects that interact with


each other to accomplish a goal.

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

ABSTRACTION refers to the act of


representing essential features without
including the background details or
explanations.
It focuses upon the observable behavior of an
object.

١٤
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.

 Data hiding is important for several reasons.


 It protects of attributes from accidental corruption by outside objects.
 It hides the details of how an object works, so the programmer can
concentrate on using it.
 It allows the maintainer of the object to have the ability to modify the
internal functioning of the object without “breaking” someone else's code.

16
Modularity

It is the property of a system that has been


decomposed into a set of cohesive and
loosely coupled modules.
It reduces complexity of program
It Creates a number of well-defined,
documented boundaries within the
program.

١٧
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

A person works for a 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:

Vehicle represents all


of the generic attributes
Vehicle Vehicle is the
and methods of a parent class.
vehicle.
“is-a” relationship

Car and Truck are Car Truck Car and Truck are
Specialized versions of child classes of
a Vehicle. Vehicle.

19
Polymorphism

 Polymorphism is the ability of objects performing the same actions


differently.

Example:
Insects have the ability to
move from one point to
another.
Insect

However, the way they


perform their movement is
different
Ant Grasshopper

Ants move by crawling Grasshoppers move by jumping

20
The Unified Modeling Language
The Unified Modeling Language

 UML stands for Unified Modelling Language.

 The UML provides a set of standard diagrams for


graphically depicting object-oriented systems

22
UML Class Diagram

 A UML diagram for a class has three main sections.

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

 To indicate the data type of a member variable, place


a colon followed by the name of the data type after
the name of the variable.
.

26
UML Parameter Type Notation

 To indicate the data type of a function’s parameter


variable, place a colon followed by the name of the
data type after the name of the variable.
.

27
UML Function Return Type Notation

 To indicate the data type of a function’s return value,


place a colon followed by the name of the data type
after the function’s parameter list.
.
.

28
The Rectangle Class

29
Showing Constructors and Destructors

30

You might also like