Didik Dwi h t t p : / / b l o g. e l e k t r o. u m. a c. i d / d i d i k Object Oriented Software...

48
Didik Dwi [email protected] h t t p : / / b l o g . e l e k t r o . u m . a c . i d / d i d i k Object Oriented Software Engineering

description

Didik Dwi - Teknik Elektro UM Paradigma Pengembangan PL  Functional Composition  Logic Programming  Structured Development  Object Orientation 3

Transcript of Didik Dwi h t t p : / / b l o g. e l e k t r o. u m. a c. i d / d i d i k Object Oriented Software...

Page 1: Didik Dwi h t t p : / / b l o g. e l e k t r o. u m. a c. i d / d i d i k Object Oriented Software Engineering.

Didik [email protected]

h t t p : / / b l o g . e l e k t r o . u m . a c . i d / d i d i k

Object Oriented Software Engineering

Page 2: Didik Dwi h t t p : / / b l o g. e l e k t r o. u m. a c. i d / d i d i k Object Oriented Software Engineering.

2Didik Dwi - Teknik Elektro UM

Subbahasan

Paradigma Pengembangan PL Prinsip Dasar Orientasi Objek Konsep Dasar Orientasi Objek

Page 3: Didik Dwi h t t p : / / b l o g. e l e k t r o. u m. a c. i d / d i d i k Object Oriented Software Engineering.

3Didik Dwi - Teknik Elektro UM

Paradigma Pengembangan PL

Functional CompositionLogic ProgrammingStructured DevelopmentObject Orientation

Page 4: Didik Dwi h t t p : / / b l o g. e l e k t r o. u m. a c. i d / d i d i k Object Oriented Software Engineering.

4Didik 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.

Page 5: Didik Dwi h t t p : / / b l o g. e l e k t r o. u m. a c. i d / d i d i k Object Oriented Software Engineering.

5Didik Dwi - Teknik Elektro UM

Logic Programming

Consists of a problem description only. e.g. Factorial(0) = 1. Factorial(N) = N x Factorial(N -1).

Doesn’t describe how to solve the problem.

Languages Prolog & Lisp support this paradigm.

Page 6: Didik Dwi h t t p : / / b l o g. e l e k t r o. u m. a c. i d / d i d i k Object Oriented Software Engineering.

6Didik Dwi - Teknik Elektro UM

Structured Development

Also called SASD, SADT & Functional Decomposition.

Breaks the system into processes & decomposes them.

Data independent from programLanguages C, Fortran, Pascal, Cobol,

Basic and a lot more support this paradigm.

By far the most popular paradigm.

Page 7: Didik Dwi h t t p : / / b l o g. e l e k t r o. u m. a c. i d / d i d i k Object Oriented Software Engineering.

7Didik 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.

Page 8: Didik Dwi h t t p : / / b l o g. e l e k t r o. u m. a c. i d / d i d i k Object Oriented Software Engineering.

8Didik Dwi - Teknik Elektro UM

Paradigma Pengembangan PL Prinsip Dasar Orientasi Objek Konsep Dasar Orientasi Objek

Page 9: Didik Dwi h t t p : / / b l o g. e l e k t r o. u m. a c. i d / d i d i k Object Oriented Software Engineering.

9Didik Dwi - Teknik Elektro UM

Basic Principles of OO

Object Orientation

Enca

psul

atio

n

Abst

ract

ion

Hier

arch

y

Mod

ular

ity

Page 10: Didik Dwi h t t p : / / b l o g. e l e k t r o. u m. a c. i d / d i d i k Object Oriented Software Engineering.

10Didik Dwi - Teknik Elektro UM

What is abstraction?

Salesperson

Not saying Which salesperson – just a salesperson in general!!!

Customer Product

Manages Complexity

Page 11: Didik Dwi h t t p : / / b l o g. e l e k t r o. u m. a c. i d / d i d i k Object Oriented Software Engineering.

11Didik Dwi - Teknik Elektro UM

What is Encapsulation?

Hide implementation from clients Clients depend on interface

Improves Resiliency

How does an object encapsulate?What does it encapsulate?

Page 12: Didik Dwi h t t p : / / b l o g. e l e k t r o. u m. a c. i d / d i d i k Object Oriented Software Engineering.

12Didik Dwi - Teknik Elektro UM

What is Modularity?

The breaking up of something complex into manageable pieces

Order Processing System

Billing

OrderEntry

OrderFulfillment

Manages Complexity

Page 13: Didik Dwi h t t p : / / b l o g. e l e k t r o. u m. a c. i d / d i d i k Object Oriented Software Engineering.

13Didik Dwi - Teknik Elektro UM

What is Hierarchy?

Levels of abstraction

Decreasing abstraction

Increasing abstraction

Asset

RealEstate

Savings

BankAccount

Checking Stock

Security

Bond

Elements at the same level of the hierarchy should be at the same level

of abstraction

Page 14: Didik Dwi h t t p : / / b l o g. e l e k t r o. u m. a c. i d / d i d i k Object Oriented Software Engineering.

14Didik Dwi - Teknik Elektro UM

Hierarchy

chairtable desk "chable"

instances of chair

furniture (superclass)

subclasses of thefurniture superclass

Page 15: Didik Dwi h t t p : / / b l o g. e l e k t r o. u m. a c. i d / d i d i k Object Oriented Software Engineering.

15Didik Dwi - Teknik Elektro UM

The OO Mindset

problem domain

objects

Page 16: Didik Dwi h t t p : / / b l o g. e l e k t r o. u m. a c. i d / d i d i k Object Oriented Software Engineering.

16Didik Dwi - Teknik Elektro UM

Paradigma Pengembangan PL Prinsip Dasar Orientasi Objek Konsep Dasar Orientasi Objek

Page 17: Didik Dwi h t t p : / / b l o g. e l e k t r o. u m. a c. i d / d i d i k Object Oriented Software Engineering.

17Didik Dwi - Teknik Elektro UM

Basic Concepts of OO

• classes and class hierarchies– instances– inheritance– abstraction and hiding

• objects– attributes– Methods– polymorphism

• Messages• Component• Package• Subsystem• Relationships

Page 18: Didik Dwi h t t p : / / b l o g. e l e k t r o. u m. a c. i d / d i d i k Object Oriented Software Engineering.

18Didik Dwi - Teknik Elektro UM

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

Page 19: Didik Dwi h t t p : / / b l o g. e l e k t r o. u m. a c. i d / d i d i k Object Oriented Software Engineering.

19Didik Dwi - Teknik Elektro UM

Representing Classes

A class is represented using a compartmented rectangle

Professor

Professor Clark

a + b = 10

Page 20: Didik Dwi h t t p : / / b l o g. e l e k t r o. u m. a c. i d / d i d i k Object Oriented Software Engineering.

20Didik Dwi - Teknik Elektro UM

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)

ProfessornameempID

create( )save( )delete( )change( )

Class Name

Attributes

Operations

Page 21: Didik Dwi h t t p : / / b l o g. e l e k t r o. u m. a c. i d / d i d i k Object Oriented Software Engineering.

21Didik Dwi - Teknik Elektro UM

Building a Class

class name

attributes:

operations:

attributes:

operations

Page 22: Didik Dwi h t t p : / / b l o g. e l e k t r o. u m. a c. i d / d i d i k Object Oriented Software Engineering.

22Didik Dwi - Teknik Elektro UM

Objects

An object is an instance of a classAn object is something that has:

State Behavior Identity

An object is a "black box" which receives and sends messages.

Page 23: Didik Dwi h t t p : / / b l o g. e l e k t r o. u m. a c. i d / d i d i k Object Oriented Software Engineering.

23Didik Dwi - Teknik Elektro UM

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

Page 24: Didik Dwi h t t p : / / b l o g. e l e k t r o. u m. a c. i d / d i d i k Object Oriented Software Engineering.

24Didik Dwi - Teknik Elektro UM

Classes and Objects

Objects are grouped into classes

Objects Class

Professor Smith

Professor Jones

Professor Mellon

Professor

Page 25: Didik Dwi h t t p : / / b l o g. e l e k t r o. u m. a c. i d / d i d i k Object Oriented Software Engineering.

25Didik Dwi - Teknik Elektro UM

What is an Attribute?

Page 26: Didik Dwi h t t p : / / b l o g. e l e k t r o. u m. a c. i d / d i d i k Object Oriented Software Engineering.

26Didik Dwi - Teknik Elektro UM

Methods

A.k.a Operations, ServicesAn executable procedure that is

encapsulated in a class and is designed to operate on one or more data attributes

CourseOffering

addStudent deleteStudentgetStartTimegetEndTime

Class

Operation

Page 27: Didik Dwi h t t p : / / b l o g. e l e k t r o. u m. a c. i d / d i d i k Object Oriented Software Engineering.

27Didik Dwi - Teknik Elektro UM

What is Polymorphism

The ability to hide many different implementations behind a single interface

Manufacturer A Manufacturer B Manufacturer C

OO Principle:Encapsulation

Page 28: Didik Dwi h t t p : / / b l o g. e l e k t r o. u m. a c. i d / d i d i k Object Oriented Software Engineering.

28Didik Dwi - Teknik Elektro UM

Messages

sender object

attributes:

operations:

receiver object

attributes:

operations:

message: [receiver, operation, parameters]

message: [sender, return value(s)]

Page 29: Didik Dwi h t t p : / / b l o g. e l e k t r o. u m. a c. i d / d i d i k Object Oriented Software Engineering.

29Didik Dwi - Teknik Elektro UM

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

OO Principle: Encapsulation

<<DLL>>ComponentName

Component Interface

Page 30: Didik Dwi h t t p : / / b l o g. e l e k t r o. u m. a c. i d / d i d i k Object Oriented Software Engineering.

30Didik Dwi - Teknik Elektro UM

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

Page 31: Didik Dwi h t t p : / / b l o g. e l e k t r o. u m. a c. i d / d i d i k Object Oriented Software Engineering.

31Didik Dwi - Teknik Elektro UM

What is a Subsystem?

A combination of a package (can contain other model elements) and a class (has behavior)

OO Principles: Encapsulation and Modularity

<<subsystem>>Subsystem Name

InterfaceInterface

RealizationSubsystem

Page 32: Didik Dwi h t t p : / / b l o g. e l e k t r o. u m. a c. i d / d i d i k Object Oriented Software Engineering.

32Didik Dwi - Teknik Elektro UM

Subsystems and Components

ComponentName

Design Model Implementation Model

<<subsystem>>Component Name

Component Interface

Component Interface

OO Principles: Encapsulation and Modularity

Page 33: Didik Dwi h t t p : / / b l o g. e l e k t r o. u m. a c. i d / d i d i k Object Oriented Software Engineering.

33Didik Dwi - Teknik Elektro UM

Relationships

Association Aggregation Composition

DependencyGeneralizationRealization

Page 34: Didik Dwi h t t p : / / b l o g. e l e k t r o. u m. a c. i d / d i d i k Object Oriented Software Engineering.

34Didik Dwi - Teknik Elektro UM

Relationships: Association

Models a semantic connection among classes

Professor UniversityWorks for

Class

Association

Association Name

Professor UniversityEmployerEmployee

Role Names

Page 35: Didik Dwi h t t p : / / b l o g. e l e k t r o. u m. a c. i d / d i d i k Object Oriented Software Engineering.

35Didik Dwi - Teknik Elektro UM

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”

Page 36: Didik Dwi h t t p : / / b l o g. e l e k t r o. u m. a c. i d / d i d i k Object Oriented Software Engineering.

36Didik Dwi - Teknik Elektro UM

Relationships: Aggregation

Contoh:

Car Body

Whole

Aggregation

Part

Page 37: Didik Dwi h t t p : / / b l o g. e l e k t r o. u m. a c. i d / d i d i k Object Oriented Software Engineering.

37Didik Dwi - Teknik Elektro UM

Relationships: Composition

A form of aggregation with strong ownership and coincident lifetimes The parts cannot survive the whole/aggregate

Book Chapter

Whole

Aggregation

Part

Page 38: Didik Dwi h t t p : / / b l o g. e l e k t r o. u m. a c. i d / d i d i k Object Oriented Software Engineering.

38Didik Dwi - Teknik Elektro UM

Multiplicity and Navigation

Multiplicity defines how many objects participate in a relationships

Associations and aggregations are bi-directional by default, but it is often desirable to restrict navigation to one direction

One direction

Bi-direction

Page 39: Didik Dwi h t t p : / / b l o g. e l e k t r o. u m. a c. i d / d i d i k Object Oriented Software Engineering.

39Didik Dwi - Teknik Elektro UM

Association: Multiplicity

UnspecifiedExactly oneZero or more (many, unlimited)

One or moreZero or oneSpecified rangeMultiple, disjoint ranges

2..4

0..1

1..*

0..*

1

*

2, 4..6

Page 40: Didik Dwi h t t p : / / b l o g. e l e k t r o. u m. a c. i d / d i d i k Object Oriented Software Engineering.

40Didik Dwi - Teknik Elektro UM

Multiplicity and Navigation

Example

Student Schedule1 0..*

Multiplicity

Navigation

Page 41: Didik Dwi h t t p : / / b l o g. e l e k t r o. u m. a c. i d / d i d i k Object Oriented Software Engineering.

41Didik Dwi - Teknik Elektro UM

Relationships: Dependency

A relationship between two model elements where a change in one may cause a change in the other

Merepresentasikan hubungan “using”

Client Supplier

Package

ClientPackage SupplierPackage

Client

Class

Dependency relationship

Page 42: Didik Dwi h t t p : / / b l o g. e l e k t r o. u m. a c. i d / d i d i k Object Oriented Software Engineering.

42Didik Dwi - Teknik Elektro UM

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”

Page 43: Didik Dwi h t t p : / / b l o g. e l e k t r o. u m. a c. i d / d i d i k Object Oriented Software Engineering.

43Didik Dwi - Teknik Elektro UM

Relationships: Generalization

One class inherits from another

Accountbalancenamenumber

Withdraw()CreateStatement()

Checking

Withdraw()

Savings

GetInterest()Withdraw()

Superclass (parent)

Subclasses

Generalization Relationship

Ancestor

Descendents

Page 44: Didik Dwi h t t p : / / b l o g. e l e k t r o. u m. a c. i d / d i d i k Object Oriented Software Engineering.

44Didik Dwi - Teknik Elektro UM

Example: Multiple Inheritance

A class can inherit from several other classes

Airplane Helicopter Wolf Horse

FlyingThing Animal

Bird

multipleinheritance

Page 45: Didik Dwi h t t p : / / b l o g. e l e k t r o. u m. a c. i d / d i d i k Object Oriented Software Engineering.

45Didik Dwi - Teknik Elektro UM

Relationships: Realization

One classifier serves as the contract that the other classifier agrees to carry out

Component

Interface

Use Case Use-Case Realization

Elided form

Class

InterfaceSubsystem

Interface

Canonical form

Page 46: Didik Dwi h t t p : / / b l o g. e l e k t r o. u m. a c. i d / d i d i k Object Oriented Software Engineering.

46Didik Dwi - Teknik Elektro UM

Tools for OO

Rumbaugh (OMT)Coad-YourdonBoochUML

Page 47: Didik Dwi h t t p : / / b l o g. e l e k t r o. u m. a c. i d / d i d i k Object Oriented Software Engineering.

47Didik Dwi - Teknik Elektro UM

Strengths of Object Orientation

Facilitates architectural and code reuseModels 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

Page 48: Didik Dwi h t t p : / / b l o g. e l e k t r o. u m. a c. i d / d i d i k Object Oriented Software Engineering.

48Didik Dwi - Teknik Elektro UM

Conclusion

Paradigma pengembangan PL: Fungsional, Logic, Structured, dan OO

Prinsip dasar orientasi objek: Abstraksi, enkapsulasi, modularity, dan

hierarkiKonsep dasar orientasi objek:

Kelas dan Objek Messages, Component, Package, Subsystem Relationships