Escolar Documentos
Profissional Documentos
Cultura Documentos
Lecture 1: OOP
Dr Dalia Fadl
Write an algorithm and draw a flowchart to log in to Facebook
account.
Answer(Algorithm)
Programs are divided into small self Programs are divided into small entities
contained functions. called objects.
less secure as there is no way of data is more secure as having data hiding
hiding. feature.
less reusability, Less abstraction and less more reusability, More abstraction and
flexibility. more flexibility.
Lecture Objectives
1. Learn the Characteristics of Object-Orientation
1. Identity
2. Classification
3. Abstraction
4. Encapsulation
5. Inheritance
6. Polymorphism
7. Genercity
3. Examples of OO Modeling
8
6-8
What is OO ?
9
1. OO Characteristics
1. Identity
2. Classification
3. Abstraction
4. Encapsulation
5. Inheritance
6. Polymorphism
7. Genercity
10
1.1 Identity
11
Identity
myCar:0x00FDA610 13
1.2 Classification
3 2
16
Abstraction
17
Abstraction
Different abstractions for the concept of a car according to the application.
Car
Car
-motorCapacity: int
ﻓﻰ ﻣﻌرض اﻟﺳﯾﺎرات -model: string
-model: string -licenseNumber: string
-make: string At Car Dealer -problem: string
-year: int
-owner: string
-licenseNumber: string -balance: float
-isFinished: bool
+Car (int, ….): void
Car
+getMake (): string
+Car (string,...): void
+printDetails(): void -model: string
-make: string +printBlanace ():string
+........ +printDetails(): void
-year: int
+........
-salePrice: int
-paymentMethod: int
19
Encapsulation
It allows you to replace an algorithm with a faster one while keeping the class
interface (public methods) the same.
22
1.5 Inheritance
23
Inheritance
Inheritance is the facility by which objects of a class (say B)
may use the methods and variables that are defined only to
objects of another class (say A), as if these methods and
variables have been defined in class B
Inheritance is represented as
shown in UML notation.
A
B
24
How to use Inheritance?
Inheritance helps building software Car
-motorCapacity: int
incrementally: -model: string
First; build classes to cope with the -make: string
most straightforward (or general) -year: int
25
1.6 Polymorphism
Polymorphism means that the same operation may behave
differently for different classes.
An operation is a procedure or a transformation that the
object performs or is subject to.
An implementation of an operation by a specific class is
called a method.
Because an OO operation is polymorphic, it may have more
than one method for implementing it, each for a different
class.
26