Object Orientation. Object Concepts. Object Concepts. Real-world Objects. Two characteristics : state behavior

Object Orientation Object Concepts • Pemrograman sebagai suatu bentuk seni • Pendekatan secara object menghasilkan disain software yang lebih baik: ...
2 downloads 2 Views 926KB Size
Object Orientation

Object Concepts

• Pemrograman sebagai suatu bentuk seni • Pendekatan secara object menghasilkan disain software yang lebih baik: modularity, reusability, maintainability • OOA/D mengikuti paradigma pengembangan perangkat keras

12-Feb-04

©2004 PM - IKI10100

2-1

Object Concepts

12-Feb-04

©2004 PM - IKI10100

2-2

Real-world Objects Two characteristics : z state z behavior Exp. a dog: - state: name, color, breed, hungry - behavior: barks, bites, runs, jumps

12-Feb-04

©2004 PM - IKI10100

2-3

12-Feb-04

©2004 PM - IKI10100

2-4

1

Software Objects

Object Model10 mph

z Modeled

after real-world objects. z Maintains states in variables and z Implements behaviors with methods

method ©2004 PM - IKI10100

z

brake

A Circle

12-Feb-04

setRadius

©2004 PM - IKI10100

2-6

zA

class is the blueprint of an object. z An object is a single instance of a class Class = Blueprint

2-7

Object = Instance of a Class

instantiation

– Modularity – Information hiding

©2004 PM - IKI10100

draw

Object and Class

Packaging an object’s variables within the protective custody of its methods. Typically, used to hide unimportant implementation details from other objects. Benefits:

12-Feb-04

move

setCenter 2-5

Encapsulation

z

color = blue

5th gear

A Bicycle

method

z

90 rpm

change cadence

method

12-Feb-04

change gears

center = (4,5) radius = (25)

12-Feb-04

©2004 PM - IKI10100

2-8

2

Object Model

Messages z

change gears brake

z

Model of a Circle move

change cadence Model of a Bicycle

draw

setRadius setCenter

12-Feb-04

©2004 PM - IKI10100

2-9

z

Software object saling berinteraksi dan berkomunikasi dengan saling mengirimkan messages. Setiap object menyediakan interface yang dapat dipakai untuk berinteraksi dengan object lain. Object A menginginkan object B untuk menampilkan suatu perilaku, maka object A mengirim message ke object B.

12-Feb-04

2 - 10

©2004 PM - IKI10100

Komponen Pesan

Inter Object Message Passing

1. Object yang dituju

changeGears(lowerGear)

2. Perilaku yang dikehendaki untuk ditampilkan (nama method dari object yang dituju) 3. Informasi yang diperlukan untuk menampilkan perilaku yang dimaksud. 12-Feb-04

©2004 PM - IKI10100

YOU

YOUR BICYCLE 2 - 11

12-Feb-04

©2004 PM - IKI10100

2 - 12

3

OOA/D Analogy

Business Processes

Document Service Company proceed

Document service company:

Production

• Photocopy (color, b/w, zoom in/out) ask_consumables

• Printing (color, b/w, poster size) • Binding • etc.

buy 2 - 13

©2004 PM - IKI10100

Document Service Company

Stock ask_consumables( ) buy( )

12-Feb-04

ask_consumables total_cost

Secretary

Billing ©2004 PM - IKI10100

2 - 14

Main Skills in OO

Customer Service order( ) notify( )

Production proceed( )

order

Technician Stock

12-Feb-04

notify repair

Customer Service

z What

does it mean to have a welldesigned object-oriented system? z How should responsibilities be allocated to classes of objects? z How should objects interact? z What classes should do what?

Technician repair( ) Secretary

Billing total_cost( ) 12-Feb-04

©2004 PM - IKI10100

2 - 15

12-Feb-04

©2004 PM - IKI10100

2 - 16

4

Object vs Function-Oriented Decomposition or

The Library Information System

Structured A/D Object-oriented A/D Catalog

Librarian

Book

Library

Decompose by objects or concepts 12-Feb-04

Discovering Inheritance

System Report Fines Decompose by functions or processes Record Loans

©2004 PM - IKI10100

Add Resources

2 - 17

„ „

Inheritance defines a relationship among classes where one class shares the structure and/or behavior of one or more classes. “Is-a” or “kind-of” hierarchy. What will be inherited from superclass? „ „ „

©2004 PM - IKI10100

2 - 18

Subclasses

What is Inheritance „

12-Feb-04

„

„

May be augmented with additional attributes and operations that apply only to that level of the hierarchy. May supply its own implementation of an operation.

Attributes Operations Relationships

12-Feb-04

©2004 PM - IKI10100

2 - 19

12-Feb-04

©2004 PM - IKI10100

2 - 20

5

Generalization „

Generalization RegistrationUser

Provides the capability to create superclass that encapsulate structure and behavior common to several classes. Student

Professor

ID Name Major

Student

ID Name Interest

12-Feb-04

©2004 PM - IKI10100

ID Name Major

2 - 21

Generalization

2 - 22

©2004 PM - IKI10100

Generalization RegistrationUser

Name ID

Major

ID Name Interest

12-Feb-04

RegistrationUser

Student

Professor

Name ID

*

Student

Professor

SportsClub

Professor

Major

Interest

0..4

Interest 3..10

1

CourseOffering 0..4 12-Feb-04

©2004 PM - IKI10100

2 - 23

12-Feb-04

0..4 ©2004 PM - IKI10100

2 - 24

6

Composition

Aggregation „

Is a kind of association used to model “whole-part” relationship between things.

Hand

„

1

0..5

The multiplicity at the composite end may be at most one, and is signified with a filled diamond.

Finger

Car

1

0..4

Tire

Default association “has-part”.

12-Feb-04

2 - 25

©2004 PM - IKI10100

Shared Aggregation „

„

Keyword

12-Feb-04

©2004 PM - IKI10100

2 - 26

How to Identify Aggregation

The multiplicity at the composite end may be more than one, and is signified with a hollow diamond. AWT Panel

12-Feb-04

*

*

*

* ©2004 PM - IKI10100

AWT Object

Book

2 - 27

The lifetime of the part is bound within the lifetime of the composite. „ There is an obvious whole-part physical or logical assembly. „ Some properties and operations of the composite propagate to the parts. „

12-Feb-04

©2004 PM - IKI10100

2 - 28

7

Aggregation Sample

Sale

Product Catalog

12-Feb-04

1

1..*

1

1..*

©2004 PM - IKI10100

Item

Product Specification

2 - 29

8