0% found this document useful (0 votes)
19 views31 pages

01 IntroductionToOOP

This document is an introduction to Object Oriented Programming (OOP) presented by Prof. Tran Minh Triet, covering key concepts such as the differences between procedural and object-oriented programming, the four principles of OOP (abstraction, encapsulation, modularity, and hierarchy), and the importance of understanding OO concepts before learning specific programming languages. It emphasizes the historical context of object technology and the significance of proper design practices in software development. Additionally, it discusses issues related to software design, including reusability, extensibility, and flexibility.

Uploaded by

minhvan9602
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)
19 views31 pages

01 IntroductionToOOP

This document is an introduction to Object Oriented Programming (OOP) presented by Prof. Tran Minh Triet, covering key concepts such as the differences between procedural and object-oriented programming, the four principles of OOP (abstraction, encapsulation, modularity, and hierarchy), and the importance of understanding OO concepts before learning specific programming languages. It emphasizes the historical context of object technology and the significance of proper design practices in software development. Additionally, it discusses issues related to software design, including reusability, extensibility, and flexibility.

Uploaded by

minhvan9602
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

Module 1:

Introduction to
Object Oriented Programming

Prof. Tran Minh Triet


1
Acknowledgement

vThis presentation reuses materials from:


§ Course CS202: Programming Systems
Instructor: MSc. Karla Fant,
Portland State University
§ Course CS202: Programming Systems
Instructor: Dr. Dinh Ba Tien,
University of Science, VNU-HCMC
§ Course DEV275: Essentials of Visual Modeling with
UML 2.0
IBM Software Group
Outline

vIntroduction
vProcedural vs. OO Programming
vFour principles of OO
vOther issues

3
Introduction…

4
The History of Object Technology

vMajor object technology milestones


Simula C ++ The UML

1967 Late 1980s 1996

1972 1991 2004

Smalltalk Java UML 2

5
Object-oriented concepts

vLearning OO concepts is not accomplished by


learning a specific development method or a
set of tools.
vBut, it is a way of thinking.

6
Object-oriented concepts (cont)

For examples:
v Many people are introduced to OO concepts via
one of these development methods or tools.
èMany C programmers were first introduced to object
orientation by migrating directly to C++, before they
were even remotely exposed to OO concepts.
èSome software professionals were first introduced to
object orientation by presentations that included
object models using UML

7
Problems!!!

vLearning a programming language is an


important step, but it is much more important
to learn OO concepts first.
§ Developers who claim to be C++ programmers are
simply C programmers using C++ compilers.
§ Learning UML before OO concepts is similar to
learning how to read an electrical diagram without
first knowing anything about electricity.

8
Even worse!!!

vA programmer can use just enough OO


features to make a program incomprehensible
to OO and non-OO programmers alike.

9
Practice

vUsing the data structure struct, implement


the following structures and functions:
§ struct Point: data structure for a 2-D point.
§ struct Triangle: contains the information of the 3
vertices
§ A function to calculate a distance between 2 points
§ Functions to calculate the perimeter and area of a
triangle.

We already know everything about OOP???


10
OO concepts

It is very important that


while you're on the road to OO
development, you first learn the
fundamental OO concepts.

11
Procedural vs. OO Programming

12
Procedural vs. OO Programming

An object is an entity
that contains both data and behaviours

vIn procedural programming:


§ Code is placed into totally distinct functions or
procedures.
§ Data is placed into separate structures, and is
manipulated by these functions or procedures.

13
Procedural vs. OO Programming (cont)

vIn OO programming: the attributes and


behaviours are contained within a single
object
vIn procedural programming: the attributes
and behaviours are normally separated.

14
Why do we change from
procedural to OO programming?

15
Why do we change from
procedural to OO programming?
vIn procedural programming:
§ Data is separated from the procedures.
§ Sometimes it is global à easy to modify data that
is outside your scope
èThis means that access to data is uncontrolled and
unpredictable.
§ Having no control over the data à testing and
debugging are much more difficult.

16
Why do we change from
procedural to OO programming?
vObjects solve these problems by combining
data and behaviours into a complete package.

vIn a proper OO design: there is no global data


(we expect ;-)

17
Objects (again!)

vObjects do contain:
§ Integers, and strings… à attributes.
§ Methods (i.e. functions) à behaviours.
vIn an object, methods are used to operate on
the data.

You can control access to


members of an object (both attributes and methods).

18
Four principles of OO

19
Basic Principles of Object Orientation

Object Orientation

Encapsulation

Modularity

Hierarchy
Abstract
ion

20
What Is Abstraction?

vThe essential characteristics of an entity


that distinguishes it from all other kinds of
entities.
vDefines a boundary relative to the
perspective of the viewer.
vIs not a concrete manifestation, denotes the
ideal essence of something.

21
Example: Abstraction

Student Professor

Course Offering (9:00 a.m.,


Monday-Wednesday-Friday)
Course (e.g. Algebra) 22
What Is Encapsulation?

w Hides implementation from clients.


§ Clients depend on interface.

Improves Resiliency 23
Encapsulation Illustrated
Ac
ce
pt
Co
ur
se
Of
fe
rin

)
s(
g(

de
)

ra
lG
Name: J Clark

na
Fi
Employee ID: 567138

it
bm
Su
HireDate: 07/25/1991
Status: Tenured

SetMaxLoad(4)

Se
Discipline: Finance

tM
MaxLoad:4

ax
Lo
ad
()
vProfessor Clark TakeSabbatical()

needs to be able
to teach four Professor Clark

classes in the next


semester. 24
What Is Modularity?

vBreaks up something complex into


manageable pieces.
vHelps people understand complex
systems.

25
Example: Modularity

vFor example, break


Billing
complex systems into System
smaller modules.

Course
Catalog
System

Course Registration
System Student
Management
System

26
What Is Hierarchy?
Increasing Asset
abstraction

BankAccount Security RealEstate

Decreasing Savings Checking Stock Bond


abstraction
Elements at the same level of the hierarchy
should be at the same level of abstraction. 27
Other issues…

28
Software Design

v Reusability
§ Portable and independent components can be reused in
many systems
v Extensibility
§ Support external plug-ins
v Flexibility
§ Change will be easy when new data/features added
§ Modifications are less likely to break the system
§ Localize effect of changes

29
Create a system: designing process

v Divide a system in terms of components


v Divide components in terms of sub-components
v Abstraction
§ Hides details of components that are irrelevant to
the current design phase
v Component identification is top-down
§ Decompose system into smaller, simple components
v Integration is bottom-up
§ Combining small components
v Design is applied using a paradigm: procedural,
modular, objectoriented
30
Abstraction

v Procedural design
§ Define set of functions to accomplish task
§ Pass information from function to function
v Modules (modular design)
§ Define modules, where each has data and procedures
§ Each module has a public and a private section
§ Works as a scoping mechanism
v Classes/Objects (object-oriented design)
§ Abstract Data Types
§ Divide project in set of cooperating classes
§ Each class has a very specific functionality
§ Classes can be used to create multiple instances of
objects
31

You might also like