Anda di halaman 1dari 49

OOSE

Didik Dwi Prasetya


didikdwi@um.ac.id

Subbahasan
Paradigma Pengembangan PL
Prinsip Dasar Orientasi Objek

Konsep Dasar Orientasi Objek

Didik Dwi - Teknik Elektro UM

Paradigma Pengembangan PL
Functional Composition
Logic Programming
Structured Development
Object Orientation

Didik Dwi - Teknik Elektro UM

Functional Composition
A problem is expressed in termed of a set

of mathematical functions.

e.g. Double(x) = Add(x, x).

An algorithm is not specified.


Language such as Miranda, Gofer, Haskell

support this paradigm.


Poor execution speed.

Didik Dwi - Teknik Elektro UM

Logic Programming
Consists of a problem description only.
e.g. Factorial(0) = 1.
Factorial(N) = N x Factorial(N -1).
Doesnt describe how to solve the

problem.
Languages Prolog & Lisp support this
paradigm.

Didik Dwi - Teknik Elektro UM

Structured Development
Also called SASD, SADT & Functional

Decomposition.
Breaks the system into processes &
decomposes them.
Data independent from program
Languages C, Fortran, Pascal, Cobol, Basic
and a lot more support this paradigm.
By far the most popular paradigm.
Didik Dwi - Teknik Elektro UM

Object Orientation
Most recent paradigm.
Treats a problem as a collection of objects.
Becoming very popular now.
More and more languages support this

paradigm now.

Didik Dwi - Teknik Elektro UM

Paradigma Pengembangan PL
Prinsip Dasar Orientasi Objek

Konsep Dasar Orientasi Objek

Didik Dwi - Teknik Elektro UM

Basic Principles of OO

Didik Dwi - Teknik Elektro UM

Hierarchy

Modularity

Encapsulation

Abstraction

Object Orientation

What is abstraction?

Salesperson
Not saying
Which
salesperson
just a
salesperson
in general!!!
Customer

Product

Manages Complexity
Didik Dwi - Teknik Elektro UM

10

What is Encapsulation?
Hide implementation from clients
Clients depend on interface

How does an object encapsulate?


What does it encapsulate?

Improves Resiliency
Didik Dwi - Teknik Elektro UM

11

What is Modularity?
The breaking up of something complex

into manageable pieces

Order Processing
System

Order
Entry

Order
Fulfillment

Billing
Manages Complexity
Didik Dwi - Teknik Elektro UM

12

What is Hierarchy?
Levels of abstraction

Asset

Increasing
abstraction

BankAccount

Security

SavingsChecking Stock
Decreasing
abstraction

RealEstate

Bond

Elements at the same level of the


hierarchy should be at the same level
of abstraction

Didik Dwi - Teknik Elektro UM

13

Hierarchy
furniture (superclass)

table

chair

desk

"chable"

subclasses of the
furniture superclass

instances of chair

Didik Dwi - Teknik Elektro UM

14

The OO Mindset

objects

problem domain

Didik Dwi - Teknik Elektro UM

15

Paradigma Pengembangan PL
Prinsip Dasar Orientasi Objek

Konsep Dasar Orientasi Objek

Didik Dwi - Teknik Elektro UM

16

Basic Concepts of OO
classes and class hierarchies

instances
inheritance
abstraction and hiding

objects

attributes
Methods
polymorphism

Messages
Component
Package
Subsystem
Relationships

Didik Dwi - Teknik Elektro UM

17

Classes
object-oriented thinking begins with the

definition of a class often defined as:

template
pattern
blueprint ... describing a collection of similar
items

OO Principle: Abstraction
Didik Dwi - Teknik Elektro UM

18

Representing Classes
A class is represented using a

compartmented rectangle

a + b = 10

Professor
Professor Clark

Didik Dwi - Teknik Elektro UM

19

Class Compartments
A class is comprised of three sections

The first section contains the class name


The second section shows the structure
(attributes)
The third section shows the behavior (operations)
Class Name
Attributes

Operations

Didik Dwi - Teknik Elektro UM

Professor
name
empID
create( )
save( )
delete( )
change( )
20

Building a Class

Didik Dwi - Teknik Elektro UM

21

Objects
An object is an instance of a class
An object is something that has:
State
Behavior
Identity

An object is a "black box" which receives

and sends messages.

Didik Dwi - Teknik Elektro UM

22

Classes and Objects


A class is an abstract definition of an

object

It defines the structure and behavior of each


object in the class
It serves as a template for creating objects

Didik Dwi - Teknik Elektro UM

23

Classes and Objects


Objects are grouped into classes

Class

Objects

Professor
Professor Smith

Professor Mellon

Professor Jones

Didik Dwi - Teknik Elektro UM

24

What is an Attribute?

Didik Dwi - Teknik Elektro UM

25

Methods
A.k.a Operations, Services
An executable procedure that is

encapsulated in a class and is designed to


operate on one or more data attributes
CourseOffering

Class

Operation

addStudent
deleteStudent
getStartTime
getEndTime

Didik Dwi - Teknik Elektro UM

26

What is Polymorphism
The ability to hide many different

implementations behind a single interface

Manufacturer A

Manufacturer B

Manufacturer C

OO Principle:
Encapsulation
Didik Dwi - Teknik Elektro UM

27

Messages

Didik Dwi - Teknik Elektro UM

28

What is a Component?
A non-trivial, nearly independent, and

replaceable part of a system


A component may be

A source code component


A run time components or
An executable component

<<DLL>>
Component
Name
Component Interface

OO Principle: Encapsulation
Didik Dwi - Teknik Elektro UM

29

What is a Package?
A package is a general purpose mechanism

for organizing elements into groups


A model element which can contain other
model elements

Package Name

OO Principle:
Modularity
Didik Dwi - Teknik Elektro UM

30

What is a Subsystem?
A combination of a package (can contain

other model elements) and a class (has


behavior)
Realization

Subsystem

<<subsystem>>
Subsystem Name

Interface

Interface

OO Principles: Encapsulation and Modularity


Didik Dwi - Teknik Elektro UM

31

Subsystems and Components

Design Model

<<subsystem>>
Component Name
Component
Interface

Implementation Model

Component
Name
Component
Interface

OO Principles: Encapsulation and Modularity

Didik Dwi - Teknik Elektro UM

32

Relationships
Association
Aggregation
Composition
Dependency
Generalization

Realization

Didik Dwi - Teknik Elektro UM

33

Relationships: Association
Models a semantic connection among

classes

Association
Name

Professor

Works for

Association
Class

University

Role Names

University

Professor
Employee Employer

Didik Dwi - Teknik Elektro UM

34

Relationships: Aggregation
A special form of association that models a

whole-part relationship between an


aggregate (the whole) and its parts
Hubungan keseluruhan sebagian
(wholepart)
Merepresentasikan hubungan has a/an

Didik Dwi - Teknik Elektro UM

35

Relationships: Aggregation
Contoh:
Whole

Part

Body

Car

Aggregation

Didik Dwi - Teknik Elektro UM

36

Relationships: Composition
A form of aggregation with strong

ownership and coincident lifetimes

The parts cannot survive the whole/aggregate


Part

Whole

Chapter

Book

Aggregation
Didik Dwi - Teknik Elektro UM

37

Multiplicity and Navigation


Multiplicity defines how many objects

participate in a relationships
Associations and aggregations are bidirectional by default, but it is often
desirable to restrict navigation to one
direction
Bi-direction

One direction

Didik Dwi - Teknik Elektro UM

38

Association: Multiplicity
Unspecified
Exactly one
Zero or more (many, unlimited)
One or more
Zero or one

Specified range
Multiple, disjoint ranges

Didik Dwi - Teknik Elektro UM

1
0..*
*
1..*

0..1
2..4
2, 4..6

39

Multiplicity and Navigation


Example

Multiplicity

Student

0..*

Schedule

Navigation

Didik Dwi - Teknik Elektro UM

40

Relationships: Dependency
A relationship between two model

elements where a change in one may


cause a change in the other
Merepresentasikan hubungan using
Client

Class
Package

ClientPackage

Didik Dwi - Teknik Elektro UM

Supplier

Dependency
relationship

Client

SupplierPackage

41

Relationships: Generalization
Defines a hierarchy of abstractions in

which a subclass inherits from one or more


superclasses

Single inheritance
Multiple inheritance

Merepresentasikan hubungan is-a-kind

of

Didik Dwi - Teknik Elektro UM

42

Relationships: Generalization
One class inherits from another
Ancestor
Account
balance
name
number

Superclass
(parent)

Withdraw()
CreateStatement()

Generalization
Relationship

Subclasses

Checking

Savings

Withdraw()

GetInterest()
Withdraw()

Descendents
Didik Dwi - Teknik Elektro UM

43

Example: Multiple Inheritance


A class can inherit from several other

classes

FlyingThing

Animal
multiple
inheritance

Airplane

Helicopter

Didik Dwi - Teknik Elektro UM

Bird

Wolf

Horse

44

Relationships: Realization
One classifier serves as the contract that

the other classifier agrees to carry out


Class

Component

Subsystem
Interface

Interface

Interface

Elided form
Canonical form

Use Case
Didik Dwi - Teknik Elektro UM

Use-Case Realization
45

Tools for OO
Rumbaugh (OMT)
Coad-Yourdon
Booch
UML

Didik Dwi - Teknik Elektro UM

46

Strengths of Object Orientation


Facilitates architectural and code reuse
Models more closely reflect the real world

More accurately describe corporate data and


processes
Decomposed based on natural partitioning
Easier to understand and maintain

Stability

A small change in requirements does not mean


massive changes in the system under
development

Didik Dwi - Teknik Elektro UM

47

Studi Kasus
Identifikasi masing-masing tiga contoh

hubungan:

Association
Aggregation
Composition
Dependency
Generalization

Diskusikan berpasangan dengan teman

sebangku

Didik Dwi - Teknik Elektro UM

48

Conclusion
Paradigma pengembangan PL:
Fungsional, Logic, Structured, dan OO
Prinsip dasar orientasi objek:
Abstraksi, enkapsulasi, modularity, dan
hierarki
Konsep dasar orientasi objek:
Kelas dan Objek
Messages, Component, Package, Subsystem
Relationships
Didik Dwi - Teknik Elektro UM

49