0% found this document useful (0 votes)
14 views

Class 13

The document discusses key object-oriented programming concepts including class, objects, inheritance, abstraction, encapsulation, polymorphism, relationships between classes like inheritance, association, aggregation and composition, and genericity. It provides definitions and examples to explain these concepts.

Uploaded by

vedidom615
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
14 views

Class 13

The document discusses key object-oriented programming concepts including class, objects, inheritance, abstraction, encapsulation, polymorphism, relationships between classes like inheritance, association, aggregation and composition, and genericity. It provides definitions and examples to explain these concepts.

Uploaded by

vedidom615
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 24

Object-Orientation

Concepts

1
Definitions
▪ Class
▪ Objects
▪ Inheritance
▪ Abstraction
▪ Encapsulation
▪ Polymorphism

2
What are the Different Types of
Relationships Among Classes?
⚫ Four types of relationships:
− Inheritance
− Association
− Aggregation/Composition
− Dependency

3
Multiple Inheritance

LibraryMember Base Class LibraryMember Base Class

Derived
Faculty Students Staff Faculty Students Staff
Classes

Multiple
Inheritance

UnderGrad PostGrad Research UnderGrad PostGrad Research

4
Association Relationship
⚫ Enables objects to communicate with
each other:
− Thusone object must “know” the
address of the corresponding object in
the association.
⚫ Usually binary:
− But in general can be n-ary.

5
Association Relationship

1 borrowed by *
Library Member Book

6
Association Relationship
⚫ A class can be associated with itself
(recursive association).
− Give an example?
⚫ An arrowhead used along with name,
indicates direction of association.
⚫ Multiplicity indicates # of instances
taking part in the association.

7
Aggregation Relationship
⚫ Represents whole-part relationship
⚫ Represented by a diamond symbol at
the composite end
⚫ Cannot be reflexive (i.e. recursive)
⚫ Not symmetric
⚫ It can be transitive

8
Aggregation Relationship

* Paragraph * Line
1 1
Document

9
Composition Relationship

⚫ Life of item is same as the order

1 *
Order Item

10
Aggregation vs. Composition
⚫ Composition:
− Composite and components have the
same life.
⚫ Aggregation:
− Lifelines are different.
⚫ Consider an order object:
− Aggregation: If order items can be
changed or deleted after placing the
order.
− Composition: Otherwise. 11
Class Dependency

Dependent Class Independent Class

Representation of dependence between classes

12
Abstraction
⚫ Consider aspects relevant for
certain purpose
− Suppress non-relevant aspects
⚫ Types of abstraction:
− Data abstraction
− Behaviour abstraction

13
Encapsulation

m4

m3
m5

m2 Data
m6

m1

Methods

Concept of encapsulation 14
Polymorphism
⚫ Denotes poly (many) morphism
(forms).
⚫ Under different situations:
− Same message to the same object
can result in different actions:
⚫ Static binding
⚫ Dynamic binding
15
An Example of Static Binding
− Class Circle{
⚫ private float x, y, radius;
⚫ private int fillType;

⚫ public create ();


⚫ public create (float x, float y, float centre);
⚫ public create (float x, float y, float centre, int
fillType);
⚫ }

16
An Example of Static Binding
cont…
⚫ A class named Circle has three definitions for
create operation
− Without any parameter, default
− Centre and radius as parameter
− Centre, radius and fillType as parameter
− Depending upon parameters, method will be invoked
− Method create is said to be overloaded

17
Dynamic Binding
⚫ A method call to an object of an
ancestor class:
− Would result in the invocation of the
method of an appropriate object of the
derived class.
⚫ Following principles are involved:
− Inheritance hierarchy
− Method overriding
− Assignment to compatible types
18
Dynamic Binding
⚫ Principle of substitutability (Liskov’s
substitutability principle):
− An object can be assigned to an object of
its ancestor class, but not vice versa.

A A a; B b;
a=b; ??
B
b=a; ??

19
Dynamic Binding
⚫ Principle of substitutability (Liskov’s
substitutability principle):
− An object can be assigned to an object of
its ancestor class, but not vice versa.

A A a; B b;
a=b; (OK)
B
b=a; (not OK)

20
Dynamic Binding
Cont …

⚫ Exact method to be bound on a


method call:
− Notpossible to determine at compile
time.
− Dynamically decided at runtime.

21
Genericity
⚫ Ability to parameterize class
definitions.
⚫ Example: class stack of different types
of elements:
− Integer stack
− Character stack
− Floating point stack
⚫ Define generic class stack:
− Later instantiate as required
22
Genericity
T
Set

insert(T)
remove(T)

Refinement

EmployeeSet

23
Thank You

24

You might also like