0% found this document useful (0 votes)
8 views26 pages

CSC2071 - Lecture 07 (OO Principles)

Uploaded by

mbilal23640
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)
8 views26 pages

CSC2071 - Lecture 07 (OO Principles)

Uploaded by

mbilal23640
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/ 26

Object Oriented Programming

CSC2071
Lecture No. 07
Muhammad Shahid
Department of Computer Science
National Textile University

[email protected]
Recap

 Arrays
 Multidimensional Arrays
‒ Rectangular arrays
‒ Jagged arrays
 Arrays as Arguments
 Arrays as Return values
 The System.Array Base Class

2 Object Oriented Programming – CSC2071


What Will You Learn Today?

 What is Object-Orientation?
 Procedural Programming Paradigm
 Object Oriented Programming Paradigm
 Benefits of Object-Orientation
 Object-Oriented Principles

3 Object Oriented Programming – CSC2071


Object-Orientation

4 Object Oriented Programming – CSC2071


Procedural Programming Paradigm

 In this paradigm (functional paradigm) the


programming unit is a function

 Program is divided into self-contained and


maintainable parts called ‘Modules’

 A module contains procedures-self-contained


code that carries out a single task

5 Object Oriented Programming – CSC2071


Procedural Programming Paradigm

 A function is a self-contained code returning


value to the calling procedure

 All computations are done by applying


functions

 Procedural paradigm separates data of


program from instructions that manipulate the
data

6 Object Oriented Programming – CSC2071


Procedural Programming Paradigm

Application Module C Procedure Y

Module A Module C Procedure X


Function P Function Q
Module B Module D Procedure Y Procedure Z

Application is divided into 4 modules Modules C carries out 3 tasks (X, Y, Z) Procedure Y calls function P and Q

Data In Data Code Data Out

Function (process the data)

7 Object Oriented Programming – CSC2071


Object Oriented Programming Para.

 Paradigm describes a system as it exists in


real life based on interactions among real
objects

 Application is modeled as collection of related


objects that interact and do the work (task)

 The programming unit is a class representing


collection of similar real world objects

8 Object Oriented Programming – CSC2071


Object Oriented Programming Para.

 Programming starts with abstraction of useful


real world objects and classes

 Application is divided into multiple packages

 OOP binds together data and the instructions


that manipulate the data into a class

9 Object Oriented Programming – CSC2071


Object Oriented Programming Para.
Application Package B Class R
Methods
Class (m1,…m7)
Package A Package B P
Data
X, y, z
Class Class
Package C Package D R
Q

Application is collection of 4 Packages Packages B contains 3 classes (P, Q, R) Class R encapsulates 7 methods
( m1.. m7) and 3 attributes ( x, y, z)

Object X of Class R

Data
Message to invoke m4() 3,8,1 Data/Object out

Object (encapsulates data+code)

10 Object Oriented Programming – CSC2071


Benefits of Object-Orientation

 Modularity
‒ Source code for an object can be maintained
independently in a class. Once created, an
object can be easily passed around inside the
system.
 Code Re-use
‒ If an object already exists, you can use that
object in the program. This allows specialists to
implement/test/debug complex, task-specific
objects, which you can then trust to run in your
own code.
11 Object Oriented Programming – CSC2071
Benefits of Object-Orientation

 Information-hiding
‒ By interacting only with an object's methods,
the details of its internal implementation remain
hidden from the outside world
 Plug-ability and debugging ease
‒ If a particular object turns out to be problematic,
you can simply remove it from the application
and plug in a different object as its replacement.
This is analogous to fixing mechanical problems
in the real world.

12 Object Oriented Programming – CSC2071


Object-Oriented Principles

13 Object Oriented Programming – CSC2071


Object-Oriented Principles

1. Encapsulation
2. Abstraction
3. Inheritance
4. Polymorphism

14 Object Oriented Programming – CSC2071


OO Principles - Encapsulation

 Encapsulation is the mechanism that binds


together the code and the data it
manipulates, and keeps both safe from
outside interference and misuse
 There are two important aspects of
encapsulation:
1) Access restriction - preventing one object
from accessing another's internal state
2) Namespaces/scopes - allowing the same
name to have different meanings in different
contexts
15 Object Oriented Programming – CSC2071
OO Principles - Encapsulation

 Encapsulation mechanisms are essential for


reducing couplings between software
components

 Many encapsulation mechanisms originated


with non-object-oriented languages

 Object-oriented languages add additional


encapsulation mechanisms

16 Object Oriented Programming – CSC2071


OO Principles - Encapsulation

 Encapsulation is the mechanism that binds


together the code and the data it
manipulates, and keeps both safe from
outside interference and misuse

17 Object Oriented Programming – CSC2071


OO Principles - Encapsulation

Private Area
No Entry Private Data

Private Functions

Public Area
Entry Allowed
Public Data

Public Functions

18 Object Oriented Programming – CSC2071


OO Principles - Abstraction

 Abstraction is the development of classes,


objects, types in terms of their interfaces and
functionality, instead of their implementation
details

 Abstraction denotes a model, a view, or some


other focused representation for an real world
object

19 Object Oriented Programming – CSC2071


OO Principles - Abstraction

 “An abstraction denotes the essential


characteristics of an object that distinguish it
from all other kinds of object and thus provide
crisply defined conceptual boundaries,
relative to the perspective of the viewer.”

[G. Booch]

20 Object Oriented Programming – CSC2071


OO Principles - Abstraction

21 Object Oriented Programming – CSC2071


OO Principles - Inheritance

 Inheritance is the process by which one


object acquires the properties of another
object
 By use of inheritance, an object need only
define all of its characteristics that make it
unique within its class, it can inherit its
general attributes from its parent
 Object-oriented programming allows classes
to inherit commonly used state and behavior
from other classes
22 Object Oriented Programming – CSC2071
OO Principles - Inheritance

Tandem Bike
Mountain Bike Road Bike

23 Object Oriented Programming – CSC2071


OO Principles - Polymorphism

 Polymorphism (from Greek, meaning ‘many


forms’) is a feature that allows same interface
to be used for a multiple class of actions
depending on context
Shape
Draw()

Line Circle Triangle Rectangle


Draw() Draw() Draw() Draw()
24 Object Oriented Programming – CSC2071
Recap

 What is Object-Orientation?
 Procedural Programming Paradigm
 Object Oriented Programming Paradigm
 Benefits of Object-Orientation
 Object-Oriented Principles

25 Object Oriented Programming – CSC2071


Questions

Object Oriented Programming – CSC2071

You might also like