0% found this document useful (0 votes)
44 views7 pages

Object Oriented Programming Concepts

This document provides an introduction to Object Oriented Programming concepts, including structured programming, abstract data types, data abstraction, and operation abstraction. It discusses how structured programming introduced concepts like modular programming and decomposition of problems into independent subproblems. Object Oriented Programming builds on these concepts by introducing abstraction of both data and operations through the use of abstract data types, which encapsulate both a data structure and a set of operations that can be applied to that data type.

Uploaded by

Prakash Chandra
Copyright
© Attribution Non-Commercial (BY-NC)
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)
44 views7 pages

Object Oriented Programming Concepts

This document provides an introduction to Object Oriented Programming concepts, including structured programming, abstract data types, data abstraction, and operation abstraction. It discusses how structured programming introduced concepts like modular programming and decomposition of problems into independent subproblems. Object Oriented Programming builds on these concepts by introducing abstraction of both data and operations through the use of abstract data types, which encapsulate both a data structure and a set of operations that can be applied to that data type.

Uploaded by

Prakash Chandra
Copyright
© Attribution Non-Commercial (BY-NC)
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/ 7

Object Oriented Programming (3rd course, group 2) 26.02.

08
1. Introduction: OOP Concepts

Programming Paradigms

OOP

Object Oriented Programming Data Abstraction

Concepts
Structured Programming

Imperative Programming

Structured Programming (I) Structured Programming (II)


Operation abstraction
ƒ Structure of a module
Input values – Interface – Implementation
Procedure
à Input data à Local data
à Output
O t t data
d t à Sequence
S off instructions
i t ti
Main
à Functionality description
block Input values
Function ƒ Language syntax
Ouput value(s) – Organization of code in blocks of instructions
Definition of functions and procedures
– Extension of the language with new operations
Calls to new functions and procedures

3 4

Structured Programming: Benefits Structured Programming: Example

ƒ Eases software development


void main ()
– Avoids repetition of work {
– Programming work decomposed in independent modules double u1, u2, m;
u1 = 4;
double module (double u1, double u2)
– Top-down
p design:
g decomposition
p into subproblems
p u2 = -2;
{
m = sqrt (u1*u1 + u2*u2);
double m;
ƒ Facilitates software maintenance printf (”%lf”, m);
m = sqrt (u1*u1 + u2*u2);
}
– Easier to read code return m;
}
– Independence of modules
void main ()
ƒ Favors software reuse {
printf (”%lf”, module (4, -2));
}

5 6

Escuela Politécnica Superior


Pablo Castells Universidad Autónoma de Madrid
Object Oriented Programming (3rd course, group 2) 26.02.08
1. Introduction: OOP Concepts

Abstract Data Types Data Abstraction

Data abstraction + operation abstraction c


z
a
x
b y
ƒ An Abstract Data Type consists of:
– Data structure which stores information to represent a certain concept

– Functionality: set of operations that can be applied to the data type

ƒ Language syntax
– Modules are associated to data types

– Not necessarily new syntax w.r.t. modular programming

7 8

Operation Abstraction TAD Example in C

struct vector {
Entrada Entrada double x;
double y;
};

void construct (vector *u, double u1, double u2)


{
u->x
u >x = u1;
arg1 arg1 arg2 arg3 u->y = u2;
}
void main ()
double module (vector u) {
{ vector u;
double m; construct (&u, 4, -2);
m = sqrt (u.x*u.x + u.y*u.y); printf (”%lf”, module (u));
return m; }

Salida Salida }

9 10

TAD Extensibility Abstract Data Types: Benefits

... ƒ Domain concepts are reflected in the code


double product (vector u, vector v)
{ ƒ Encapsulation: internal complexity, data and operation details are hidden
return u.x * v.x + u.y * v.y;
} ƒ Specification vs.
vs implementation: usage of data type is independent from its
void main ()
internal implementation
{
vector u, v;
construct (&u, 4, -2); ƒ Higher modularity: also data
construct (&v, 1, 5);
printf (”%lf”, product (u, v));
ƒ Increases ease of maintenance and reuse of code
}

11 12

Escuela Politécnica Superior


Pablo Castells Universidad Autónoma de Madrid
Object Oriented Programming (3rd course, group 2) 26.02.08
1. Introduction: OOP Concepts

Object Oriented Programming (I)


Object Oriented Programming
) ƒƒ Explicit syntactic support for data abstraction
Change of point of view: programs are appendices of data
Object Oriented Programming ƒ A new concept appears: object
= Object = abstract data type with state (attributes) and behavior (operations)
Syntactic support for abstract data types )ƒ The concept of class hierarchy is introduced, and with it:
– Inheritance of structure and functionality
+
– Type polivalence Functions
Facilities associated to class hierarchies
– Polimorfism Object
+
ƒ Language syntax:
Change of perspective – Class definitions
Variables
– Functions explcitly associated to classes
– Creation of objects
– Access to attributes, method invocation
13 14

Object Oriented Programming


Object Oriented Programming (II)
Example in Java
class Vector {
private double x;
private double y;
Vector (double u1, double u2) { x = u1; y = u2; }
double module () { return Math
Math.sqrt
sqrt (x*x
(x x + y*y);
y y); }
}

class MainClass {
public static void main (String args []) {
Vector u = new Vector (4, -2);
System.out.println (u.module ());
}
}

15 16

Object Oriented Programming


Example in C++ Object Oriented Programming: Benefits
class Vector { ƒ Benefits of data abstraction + programming methodology
private:
double x;
double y; Code reuse and maintenance, extension of applications
public:
Vector (double u1, double u2) { x = u1; y = u2; } C
Component-oriented
t i t d software
ft development
d l t and
d iintegration
t ti
double module () { return sqrt (x*x + y*y); }
}; ƒ Language power: inheritance, polimorfism
void main ()
{ ƒ Reflect concepts of problem domains
Vector u (4, -2);
cout << u.module (); ƒ ¿Easier to use?
}

17 18

Escuela Politécnica Superior


Pablo Castells Universidad Autónoma de Madrid
Object Oriented Programming (3rd course, group 2) 26.02.08
1. Introduction: OOP Concepts

OO Languages OOP Elements


ƒ Simula (1967)
ƒ Objects: attributes + methods
ƒ Smalltalk (1980)
ƒ Methods: operations on objects
ƒ C++ (1983, 1990)
ƒ Object Pascal (1988) ƒ Classes: categories
g of objects
j with common p
properties
p and operations
p
ƒ Lisp CLOS (1989) ƒ Class hierarchies
ƒ Java (1995, 1997, 1998...)
ƒ In some languages classes are objects
– Particular case: prototype-instance paradigm
Pure vs. hybrid languages
ƒ Relations, composite objects

19 20

Conceptual Structure of an Object Relations between Objects


name name
birth birth
ƒ Properties: values Employee division Manager division
gross salary gross salary ƒ Types of relations
category
– Specialization: only between classes
ƒ Relations with other objects Employee
Manager – Aggregation: composite objects made of parts
– Association: arbitrary relations (e.g. supervisor of an employee)
ƒ Methods: code Employee

– Access to object state ƒ Implementation


show
– Calculations over state personal – Specific language elements for relations
Employee
– Modification of state data
– Regular attributes that contain references (pointers) to objects
– Constructors: initialization
calculate
net salary

21 22

Objects and Encapsulation Object Life Cycle


ƒ Creation
ƒ Visible part: interface
Memory allocation: Employee x = create Employee (···)
– Public contract of behavior
Initialization of attributes: constructors
– Description of operations: input and output information ƒ Manipulation
Access to attributes: x . name
ƒ Hidden part: implementation Data
Method invocation: x . net_salary ( )
– Data structure to store the information
ƒ Destruction
– Code that is executed to perform operations Free memory
Destroy parts, if any
Interface
Methods Remove references to the destroyed object (e.g. supervisor)

23 24

Escuela Politécnica Superior


Pablo Castells Universidad Autónoma de Madrid
Object Oriented Programming (3rd course, group 2) 26.02.08
1. Introduction: OOP Concepts

Object Hierarchy Structure Inheritance


name
Person Person
Type hierarchy birth

Person x
Employee y = create Employee
division name off company
p y
Employee
l Customer Manager z = create Manager Employee
l Customer
gross salary contact phone number
x=y
x=z
Manager category Manager

25 26

Functionality Inheritance Ease of Extension


show
personal
data Reuse
Person
specialization specialization
Person

Modularity
y calculate
net salary Employee
l Customer
calculate show show
net salary personal Employee Customer personal
data data

inheritance show
personal Administrative Manager
show data
calculate personal
net salary Manager
data

27 28

Multiple Inheritance Ambiguity in Multiple Inheritance


x
year year of graduation
courses Student MSc specialty A
register (course) qualifications

y y
B C D obj = create D
t z
Graduate
Student obj . x
obj . y
year of graduation
specialty D
qualifications
year x
courses y
register (course) z
t

29 30

Escuela Politécnica Superior


Pablo Castells Universidad Autónoma de Madrid
Object Oriented Programming (3rd course, group 2) 26.02.08
1. Introduction: OOP Concepts

Polimorfism Dynamic Linking


ƒ Overloading ƒ Dynamic linking Calculate area of selected figure
Line l1 = create Line Person x
Line l2 = create Line Employee y = create Employee area ( )
Vector v = create Vector x=y
l1.parallel (r2) x.show data ( )
x.show_data Figure
g
l1.parallel (v) y.show_data ( )
ƒ Overriding (specialization)
Person x = create Person
Employee y = create Employee Triangle Rectangle Ellipse
x.show_data ( )
area ( ) area ( ) area ( )
y.show_data ( )

31 32

Dynamic Linking of Arguments Dynamic Linking of Arguments:


Ambiguity (I)
Calculate area of the intersection of selected figures
Triángle f (A x, B y)
A C
double intersection (Triangle t) f (B x, A y)
double intersection (Ellipse e)
double intersection (Rectangle r)
Rectangle
double intersection (Triangle t)
double intersection (Ellipse e) B
B b1 = create B
double intersection (Rectangle r) ?
Ellipse B b2 = create B
double intersection (Triangle t) C c = create C
double intersection (Ellipse e)
c . f (b1, b2)
double intersection (Rectangle r)

33 34

Dynamic Linking of Arguments: Dynamic Linking of Arguments:


Ambiguity (II) Ambiguity (III)

f (B x) f (A x)
A A B D
f (B x)
B b = create B
? b . f (b) C
?
B f (A x)

C c = create C
D d = create D
d . f (c)

35 36

Escuela Politécnica Superior


Pablo Castells Universidad Autónoma de Madrid
Object Oriented Programming (3rd course, group 2) 26.02.08
1. Introduction: OOP Concepts

Person Computer
OO Analysis and Design:

Diagram
Class
name : String 1..* Uses 0..* name : String
Unified Modeling Language (UML) birth : Date memory : Integer

Class Object
Attributes Attributes Interface User1 : Person Serer7 : Computer

name = "John"
John name = "Andromeda"
Andromeda
Operations Operations birth = 21/07/76 memory = 256

Object Diagram
Dependence
User2 : Person PC12 : Computer
Generalization
name = "Louis" name = "Anubis"
Asociation age = 21/07/85 memory = 128

Aggregation

37 38

Figure
{abstract}
Formed by * position : Point * Formed by
Canvas

draw ( ) {abstract}
area ( ) : Integer {abstract}

Group Circle Polygon Point


Formed
center : Point x : Integer
by
radio : Integer y : Integer
*
draw ( ) draw ( ) draw ( )
area ( ) : Integer area ( ) : Integer area ( ) : Integer

39

Escuela Politécnica Superior


Pablo Castells Universidad Autónoma de Madrid

You might also like