73
1 Introduction to Introduction to Object Object Oriented Oriented Technology Technology

Introduction to Object Oriented Technology

  • Upload
    allayna

  • View
    90

  • Download
    5

Embed Size (px)

DESCRIPTION

Introduction to Object Oriented Technology. Contents. Computational Model Why object orientation two responses to software crisis Key 00 concepts object, class, message passing, inheritance, encapsulation What is “object oriented” object oriented user interfaces - PowerPoint PPT Presentation

Citation preview

Page 1: Introduction to Object Oriented Technology

1

Introduction Introduction to Objectto ObjectOriented Oriented TechnologyTechnology

Page 2: Introduction to Object Oriented Technology

2

ContentsContents Computational ModelComputational Model Why object orientationWhy object orientation

– two responses to software two responses to software crisiscrisis

Key 00 conceptsKey 00 concepts– object, class, message passing, object, class, message passing, inheritance, encapsulationinheritance, encapsulation

What is “object oriented”What is “object oriented”– object oriented user interfacesobject oriented user interfaces– object oriented software object oriented software design and analysis methodsdesign and analysis methods

– object oriented databasesobject oriented databases– object oriented programming object oriented programming languageslanguages

– object oriented integrated object oriented integrated systemssystems

Page 3: Introduction to Object Oriented Technology

3

Computational Computational ModelModel

Sequential programs Sequential programs– Assembly language, Pascal , C Assembly language, Pascal , C– Turing Machines Turing Machines

Recursive functions Recursive functions– LispsLisps

Recursive relations Recursive relations– Prologs, predicate calculus Prologs, predicate calculus

Data Flow Data Flow– Dataflow diagrams[Yourdon, Dataflow diagrams[Yourdon,

DeMarco]DeMarco] Pertri Nets, State machines Pertri Nets, State machines

Page 4: Introduction to Object Oriented Technology

4

ConventionalConventional Programming: Programming:ImparativeImparative Programming ProgrammingControl

data

• Algorithm = Data + Control• Based on the computation model of von Neumann• machines: assembly language, FORTRAN, Pascal, C,etc• - Centralized control think globaly

Page 5: Introduction to Object Oriented Technology

5

Progr ams

Data

Procedural Programming

โปรแกรมและข้�อม ลอยู่ �คนละส่�วน

Page 6: Introduction to Object Oriented Technology

6

Program Program CodingCodingDeclaration

Integer

Real

Character

Boolean

Array

Record

ต้�องประกาศชื่��อต้�วแปรทุ�กคร��ง

Page 7: Introduction to Object Oriented Technology

7

Program Program CodingCodingDeclarationData Input

Text & NumericRecordsImage

Voice

Sound

ต้�องเข้ ยู่นค!าส่��งทุ �แต้กต้�าง

ก�น เพื่��อทุ �จะให้�ร�บข้�อม ลข้องแต้�ละอ�ปกรณ์(

ร�บข้�อม ล

Page 8: Introduction to Object Oriented Technology

8

Program Program CodingCodingDeclarationData Input Processing

Computing

ProcedureFunction

LoopingSelec

tion• If• Case

โปรแกรมประยู่�กต้(

ข้นาดให้ญ่�ต้�องเข้ ยู่นค!าส่��งประมวลผลข้�อม ลต้�อเน��องก�นห้ลายู่ร�อยู่ห้ร�อห้ลายู่พื่�น

บรรทุ�ด เม��อเก,ดข้�อผ,ด

พื่ลาด ทุ!าให้�ยู่ากต้�อการค�นห้า

Page 9: Introduction to Object Oriented Technology

9

DeclarationData Input Processing

Program Coding

DataOutPut

Text , Graphics and Animation

Sound

Text & Graphics ค!าส่��งให้�แส่ดงผล ม ความยู่��งยู่ากซั�บซั�อน ไม�แต้กต้�าง

ไปจากการร�บข้�อม ล

Page 10: Introduction to Object Oriented Technology

10

Why object Why object orientationorientation Software crisis Software crisis

– การพั�ฒนาของฮาร�ดแวร�เร�วมาก การพั�ฒนาของฮาร�ดแวร�เร�วมาก (the (the Moore law) Moore law)

– แต่�การพั�ฒนาของซอฟต่�แวร�ช้�าและม�แต่�การพั�ฒนาของซอฟต่�แวร�ช้�าและม� bug … bug …

– ในปี ในปี 1979 1979 ร�ฐบาบ ร�ฐบาบ USUSA A ใช้�จ่�ายในใช้�จ่�ายในการพั�ฒนาซอฟต่�แวร�ด�งกราฟการพั�ฒนาซอฟต่�แวร�ด�งกราฟPayed, never finished

Major changes requiredDelivered , not used

Usefull with minor changes

Page 11: Introduction to Object Oriented Technology

11

The reasons for The reasons for software crisissoftware crisis

ช้�องว�างระหว�าง ช้�องว�างระหว�าง users users และ และ programmersprogrammers การเปีล�&ยนแปีลงการเปีล�&ยนแปีลง(change)(change) การพั�ฒนาฮาร�ดแวร�ที่�&ม�ปีระสิ)ที่ธิ)ภาพัมาก ที่,าให� การพั�ฒนาฮาร�ดแวร�ที่�&ม�ปีระสิ)ที่ธิ)ภาพัมาก ที่,าให�

ซอฟต่�แวร�ที่�& ต่�องใช้� ม�ความซ�บซ�อนมากต่ามไปีด�วย ซอฟต่�แวร�ที่�& ต่�องใช้� ม�ความซ�บซ�อนมากต่ามไปีด�วย The responses to the crisisThe responses to the crisis : : ว)ศวกรรมซอฟต่�แวร�ว)ศวกรรมซอฟต่�แวร� paradigmsparadigms ใหม�สิ,าหร�บ ใหม�สิ,าหร�บ decomposition decomposition

ของซอฟต่�แวร�และการออกแบบและว)เคราะห�ของซอฟต่�แวร�และการออกแบบและว)เคราะห�ปี0ญหาปี0ญหา

Page 12: Introduction to Object Oriented Technology

12

Software Software engineeringengineering

illustration of software engineering rationale

TestingMaintenance

ImplementationDesign

Implementation

MaintenanceTesting

Page 13: Introduction to Object Oriented Technology

13

Software Software engineeringengineering ““art of computer programming” art of computer programming”

แบบเด)มถู3กแที่นด�วย แบบเด)มถู3กแที่นด�วย engineering design engineering design และ และ planning techniques planning techniques เพั4&อใช้�ในการเพั4&อใช้�ในการ

พั�ฒนาโปีรแกรมพั�ฒนาโปีรแกรม– สิน�บสิน6นโดยซอฟต่�แวร� สิน�บสิน6นโดยซอฟต่�แวร� CASE (computer aided CASE (computer aided

soft engineering) soft engineering) Early software engineeringEarly software engineering

– ไม�ให�เก)ดการเปีล�&ยนแปีลงโดยพัยายามใช้�การหา ไม�ให�เก)ดการเปีล�&ยนแปีลงโดยพัยายามใช้�การหาrequirementsrequirements และ และ designdesign

– สิน�บสิน6นการใช้� สิน�บสิน6นการใช้� re-use of components re-use of components (programs, functions, objects)(programs, functions, objects)

– management of complexity of software management of complexity of software (decomposition)(decomposition)

OO software engineeringOO software engineering– Plan for change, ease changePlan for change, ease change– reuse of higher level componentsreuse of higher level components– new ways of decompositionnew ways of decomposition

Page 14: Introduction to Object Oriented Technology

14

The cost of changeThe cost of change60 - 100 x

1.5 - 6 x

1 x

Cost

of

ch

an

ge

design developmentmaintenance

Page 15: Introduction to Object Oriented Technology

15

DecompositionDecomposition เปี7นว)ธิ�การปีกต่)ที่�&มน6ษย�ใช้�แก�ปี0ญหาที่�&ม�ความเปี7นว)ธิ�การปีกต่)ที่�&มน6ษย�ใช้�แก�ปี0ญหาที่�&ม�ความ

ซ�บซ�อนมาก ๆ ซ�บซ�อนมาก ๆ ม�หลายว)ธิ�ที่�&ใช้�สิ,าหร�บ ม�หลายว)ธิ�ที่�&ใช้�สิ,าหร�บ software software

decomposition : decomposition :

Function oriented Function oriented– Focus : simulation some functional Focus : simulation some functional

behavior of the real world behavior of the real world Information oriented Information oriented

– Focus : the abstraction (modeling) Focus : the abstraction (modeling) the information about the real world the information about the real world

Page 16: Introduction to Object Oriented Technology

16

Software Software decomposition decomposition

(cont.)(cont.) Process orientedProcess oriented– focus : the (business) processes and focus : the (business) processes and interactions among participantsinteractions among participants

object oriented:object oriented:– focus : objects which include focus : objects which include information and functionalityinformation and functionality

component oriented:component oriented:– focus : components of applications focus : components of applications available to other softwareavailable to other software

Page 17: Introduction to Object Oriented Technology

17

History of OOHistory of OO 1970s - basic research at Xerox PARC1970s - basic research at Xerox PARC 1981 - Smalltalk language - first 1981 - Smalltalk language - first

popular OO language and operating popular OO language and operating systemsystem

1984 - object Oriented GUI on Apple 1984 - object Oriented GUI on Apple MacintoshMacintosh

1984 - C++ language … OO language 1984 - C++ language … OO language to write real softwareto write real software

1990s - development of C++ 1990s - development of C++ language and several OO analysis language and several OO analysis and design methodsand design methods

1995 - Java language … OO language 1995 - Java language … OO language for the Webfor the Web

Page 18: Introduction to Object Oriented Technology

18

OO View of the OO View of the worldworld The world can be broken into The world can be broken into

“objects”“objects”– e.g. a doge.g. a dog

objects are things :objects are things :– we have information about (dog‘s we have information about (dog‘s

name, age ...)name, age ...)– we do something to (ask a dog to fetch we do something to (ask a dog to fetch

slippers)slippers) objects are similarobjects are similar

– all dogs are similar … they belong to a all dogs are similar … they belong to a class of dogsclass of dogs

– difference between a generic concept difference between a generic concept (dogs) and instances (Lessee)(dogs) and instances (Lessee)

– classes are similar to other classes classes are similar to other classes (e.g. all dogs are animals, all animals (e.g. all dogs are animals, all animals have age, so dogs have age too . )have age, so dogs have age too . )

Page 19: Introduction to Object Oriented Technology

19

OO View of the OO View of the World (2)World (2)

ว)ธิ�การของ ว)ธิ�การของ OO OO ที่,าให�เราเข�าใจ่สิ)&งต่�างๆในโลกที่,าให�เราเข�าใจ่สิ)&งต่�างๆในโลก , ,ปี:ญหาต่�างๆรอบต่�วเราในร3ปีของปี:ญหาต่�างๆรอบต่�วเราในร3ปีของว�ต่ถู6ว�ต่ถู6 ( objects) ( objects) และ และ classesclasses

to organize classes into hierarchies to organize classes into hierarchies (Pluto, dog, animal) … from (Pluto, dog, animal) … from

instance to a very generic term instance to a very generic term the origins of object oriented view the origins of object oriented view

can be traced back to Aristotle can be traced back to Aristotle– Man is a rational animal. Man is a rational animal.– Man, animal … classes of things Man, animal … classes of things– animals … genus animals … genus– rational … differential rational … differential

Page 20: Introduction to Object Oriented Technology

20

OO and information OO and information modeling techniquesmodeling techniques

Constructs in information Constructs in information modeling techniquesmodeling techniques– entity, attribute, relationship entity, attribute, relationship

…… can be mapped into OO can be mapped into OO

constructsconstructs– object, data property, pointer object, data property, pointer

to other object to other object

Page 21: Introduction to Object Oriented Technology

21

What is an object What is an object?? ว�ต่ถู6 (object) เปี7น collection

ของ data (Attribute , properties) และ function logic

ซ;&ง data จ่ะบอกถู;งค6ณสิมบ�ต่)หร4อ สิถูานะของ Object และ Method จ่ะ

บอกถู;งพัฤต่)กรรมต่�างๆของ object น�>นๆ

Page 22: Introduction to Object Oriented Technology

22

What is an object What is an object? ? 2( )2( )

object = data structure + object = data structure + behaviorbehavior

tight couplingtight coupling Software = Collection of Software = Collection of

objects that send each objects that send each other messagesother messagesm1

m2

m4

m3

Page 23: Introduction to Object Oriented Technology

23

What is an What is an object(3)object(3)

Attribute Attribute ค4อข�อม3ลที่�&เราสินใจ่เก�&ยวก�บ ค4อข�อม3ลที่�&เราสินใจ่เก�&ยวก�บ Object Object น�>นน�>น

Method Method จ่ะแบ�งเปี7น จ่ะแบ�งเปี7น 2 2 ปีระเภที่ค4อ ปีระเภที่ค4อ interface interface method (method ( เปี7น เปี7น method method ที่�&ถู3กใช้�ได�จ่าก ที่�&ถู3กใช้�ได�จ่ากObject Object อ4&นอ4&น) ) และ และ internal method (internal method ( เปี7น เปี7นmethod method ที่�&จ่ะถู3กเร�ยกใช้�ได�เฉพัาะภายใน ที่�&จ่ะถู3กเร�ยกใช้�ได�เฉพัาะภายในObject Object ที่�&เปี7นเจ่�าของเที่�าน�>นที่�&เปี7นเจ่�าของเที่�าน�>น))

ต่�วอย�างต่�วอย�าง– circle : x, y, r, area() = 2,3,5,15circle : x, y, r, area() = 2,3,5,15– a slidea slide– a world documenta world document area()

x = 2y = 3r = 5

Circle #23223

Page 24: Introduction to Object Oriented Technology

24

Objects are Objects are defined bydefined by Variables Variables ใช้�ในการเก�บข�อม3ลใช้�ในการเก�บข�อม3ล Methods Methods ใช้�ด,าเน)นการก�บ ใช้�ด,าเน)นการก�บ datadata

Page 25: Introduction to Object Oriented Technology

25

The nature of objectThe nature of object

ว�ต้ถุ�

ม ชื่ ว,ต้

ไม�ม ชื่ ว,ต้

Page 26: Introduction to Object Oriented Technology

26

นาฬิ)กาเร4อนน�>เปี7น ว�ต่ถู6 นาฬิ)กาเร4อนน�>เปี7น ว�ต่ถู6((ObjectObject ) ) ไม�ม�ช้�ว)ต่ไม�ม�ช้�ว)ต่

แต่�ที่,างาน(เด)น) ได�เพัราะม�กลไกที่�&จ่ะที่,าให�เข�มที่�>งสิองเคล4&อนที่�&

แบบสิ�มพั�นธิ�ก�นได�

Page 27: Introduction to Object Oriented Technology

27

การก,าหนด ข�>นต่อน และว)ธิ�ที่�&จ่ะให�ก�บ นาฬิ)กาเด)นได� ที่,าได�ด�วยการบรรจ่6

กลไก และ/ หร4อ กระแสิไฟฟAาเข�าไปี เช้�น เฟBองนาฬิ)กาก�บลาน หร4อเฟBอง

นาฬิ)กาก�บกระแสิไฟฟAา การกระที่,า เช้�นน�>เร�ยกว�า การก,าหนดว)ธิ�การกระที่,า

(Method) ให�ก�บว�ต่ถู6

Page 28: Introduction to Object Oriented Technology

28

ว�ต่ถู6ที่�&ไม�ม�ช้�ว)ต่ จ่ะไม�เร)&มที่,างานด�วย ต่�วเอง ถู;งแม�จ่ะใสิ�ว)ธิ�การกระที่,าไว�

เร�ยบร�อยแล�ว หากต่�องการให�ว�ต่ถู6 ที่,างาน ต่�องม�เหต่6การณ� (Event )

จ่ากว�ต่ถู6อ4&นมากระที่บ

Page 29: Introduction to Object Oriented Technology

29

Message passingMessage passing ค4อการที่�& ว�ต่ถู6ต่)ดต่�อก�นด�วยการสิ�งข�อความ ค4อการที่�& ว�ต่ถู6ต่)ดต่�อก�นด�วยการสิ�งข�อความ

(message) (message) ถู;งก�นและก�นซ;&งข�อความจ่ะปีระกอบถู;งก�นและก�นซ;&งข�อความจ่ะปีระกอบ ด�วยจ่6ดหมายปีลายที่าง ด�วยจ่6ดหมายปีลายที่าง (destination) (destination) ของของ

ข�อความน�>นและข�อม3ลที่�&สิ,าค�ญ ข�อความน�>นและข�อม3ลที่�&สิ,าค�ญ (argument (argument หร4อ หร4อparameter)parameter)

Message Passing Message Passing เปีร�ยบได�ก�บ เปีร�ยบได�ก�บ function function call call หร4อ หร4อ procedure call procedure call ที่�&ม�ใน ที่�&ม�ใน structured structured programming programming โดยผ่�าน โดยผ่�าน InterfaceInterface

method method ของ ของ Object Object น�>นๆ ม�ผ่ลที่,าให� น�>นๆ ม�ผ่ลที่,าให�Object Object ที่�&เปี7นผ่3�ร�บข�อความ ที่�&เปี7นผ่3�ร�บข�อความ (received object) (received object) น�>นกระที่,าน�>นกระที่,า

การอย�างใดอย�างหน;&งการอย�างใดอย�างหน;&ง

Page 30: Introduction to Object Oriented Technology

30

Message passingMessage passing ว�ต่ถู6หน;&งสิามารถูสิ�ง ว�ต่ถู6หน;&งสิามารถูสิ�ง message message ถู;งก�นถู;งก�น

และก�นได�และก�นได� RECEIVER determines the RECEIVER determines the

code to be executedcode to be executed– Procedural language: Procedural language:

function name + scope function name + scope codecode

– OO language:OO language:message name + receiving message name + receiving objectobject code code

Page 31: Introduction to Object Oriented Technology

31

Object Object collaborationcollaboration

messages messages ปีระกอบด�วย ปีระกอบด�วยcomponents components ด�งน�>ด�งน�>– addressaddress– methodmethod– parametersparameters

the reply is an objectthe reply is an objectWhat is your area ?

15.232

Page 32: Introduction to Object Oriented Technology

32

Features of objectsFeatures of objects IdentityIdentity ClassificationClassification InheritanceInheritance PolymorphismPolymorphism Information hidingInformation hiding

Page 33: Introduction to Object Oriented Technology

33

IdentityIdentity Data is associated with discrete Data is associated with discrete

differentiable entitiesdifferentiable entities Object has a built-in identityObject has a built-in identity

two objects with identical data two objects with identical data are are

allowedallowed Object identity can be realized by Object identity can be realized by

unique name/key, pointerunique name/key, pointer Objects are accessed via the Objects are accessed via the

unique idunique idmixed collections are possiblemixed collections are possible

Page 34: Introduction to Object Oriented Technology

34

Class and InstanceClass and Instance Class Class เปี7นพั)มพั�เข�ยวของ เปี7นพั)มพั�เข�ยวของ Object Object

ไม�สิามารถูน,ามาใช้�ได�โดยต่รง โดยจ่ะม� ไม�สิามารถูน,ามาใช้�ได�โดยต่รง โดยจ่ะม� การบอกถู;ง การบอกถู;ง Method Method ที่�&ใช้�ได�โดย ที่�&ใช้�ได�โดย

Object Object และม�การแสิดง และม�การแสิดง data data type type ที่�&บอกถู;งสิถูานะของ ที่�&บอกถู;งสิถูานะของ Object Object

โดยย�งไม�ระบ6ค�าใน โดยย�งไม�ระบ6ค�าใน Attribute Attribute แต่�ละแต่�ละต่�วต่�ว

ถู�าเปี7น ถู�าเปี7น ObjectObject จ่ะม�การระบ6ค�าของ จ่ะม�การระบ6ค�าของAttribute Attribute ที่�&แน�นอนที่�&แน�นอน

Page 35: Introduction to Object Oriented Technology

35

ClassificationClassification Class : Grouping of similar objects:Class : Grouping of similar objects:

same attributes (instance same attributes (instance

variables)variables)

same operations same operations

(services/messages)(services/messages)

Class: abstraction to relevant featuresClass: abstraction to relevant features– Definition of classes is determined by Definition of classes is determined by

the application the application – Class describes (infinite) set of objects = Class describes (infinite) set of objects =

instances of the classinstances of the class

Page 36: Introduction to Object Oriented Technology

36

ClassClass

Page 37: Introduction to Object Oriented Technology

37

Example: class Example: class polygonpolygon

class polygonclass polygon– attributesattributes

• set of pointsset of points• line colorline color• fill colorfill color

– operationsoperations• drawdraw• deletedelete• movemove

Page 38: Introduction to Object Oriented Technology

38

Objects and Objects and classesclasses

ว�ต่ถู6แบบเด�ยวก�นจ่ะอย3�ในว�ต่ถู6แบบเด�ยวก�นจ่ะอย3�ใน class class เด�ยวก�นเด�ยวก�น , , ว�ต่ถู6ช้น)ดเด�ยวก�นจ่ะเปี7นสิมาช้)กของ ว�ต่ถู6ช้น)ดเด�ยวก�นจ่ะเปี7นสิมาช้)กของ class class

เด�ยวก�นเด�ยวก�น circle circle เปี7น เปี7น class class ของว�ต่ถู6ซ;&งม� ของว�ต่ถู6ซ;&งม� x,y,r x,y,r และและ

สิามารถูค,านวณหาพั4>นที่�&ได�จ่ากสิ3ต่ร สิามารถูค,านวณหาพั4>นที่�&ได�จ่ากสิ3ต่ร a = r a = r22 objects are objects are instances instances of classes of classes

… circle number #23 at (x,y) = … circle number #23 at (x,y) = (2,3) with r = 5 (2,3) with r = 5

Page 39: Introduction to Object Oriented Technology

39

Class versus typeClass versus type OO type OO type

= protocol understood by an = protocol understood by an object object = set of methods that are = set of methods that are implementedimplemented

Class = Class = implementation oriented implementation oriented constructconstruct– implements one or more typesimplements one or more types

Type: Used for specificationType: Used for specification

Page 40: Introduction to Object Oriented Technology

40

Features of object Features of object oriented systemsoriented systems

Classes Classes เปี7น เปี7น abstract data types abstract data types Concept Concept และ และ implementation implementation

ของของ class class จ่ะแยกจ่ากก�นจ่ะแยกจ่ากก�น Classes Classes ม�ล�กษณะ ม�ล�กษณะ hierarchicallyhierarchically

ordered, Child classes ordered, Child classes สิ4บที่อดค6ณสิมบ�ต่) สิ4บที่อดค6ณสิมบ�ต่) (data, methods) (data, methods) จ่าก จ่าก parent classes parent classes

– circle class from shape class circle class from shape class การเข�าถู;งค6ณสิมบ�ต่)ของว�ต่ถู6ขะถู3ก การเข�าถู;งค6ณสิมบ�ต่)ของว�ต่ถู6ขะถู3ก

controlled. controlled. ค6ณสิมบ�ต่)น�>ค4อ ค6ณสิมบ�ต่)น�>ค4อ encapsulation encapsulation และ และ data hiding. data hiding.

Page 41: Introduction to Object Oriented Technology

41

Abstract data Abstract data typingtyping

Circle : x, y, r; area()Circle : x, y, r; area() circle circle เปี7นสิ)&งที่�&ม�ข�อม3ลปีระกอบด�วยเปี7นสิ)&งที่�&ม�ข�อม3ลปีระกอบด�วย

ต่,าแหน�งและร�ศม� และ ต่,าแหน�งและร�ศม� และ method method ที่�&ใช้�ที่�&ใช้�ค,านวณพั4>นที่�&ค,านวณพั4>นที่�&

จ่ากน)ยามของ จ่ากน)ยามของ Circle Circle ข�างต่�นข�างต่�นccเราจ่ะเราจ่ะที่ราบถู;งว)ธิ�การค,านวณหาพั4>นที่�&ที่ราบถู;งว)ธิ�การค,านวณหาพั4>นที่�&

concept concept และ และ implementation implementation จ่ะถู3กด,าเน)นการแยกจ่ากก�นจ่ะถู3กด,าเน)นการแยกจ่ากก�น

Page 42: Introduction to Object Oriented Technology

42

InheritanceInheritance การถู�ายที่อดค6ณสิมบ�ต่) ค4อการ การถู�ายที่อดค6ณสิมบ�ต่) ค4อการ class class ที่�&ที่�&

ต่�างก�นม�ต่�างก�นม� attributes attributes และ และoperations operations ที่�&เหม4อนก�นที่�&เหม4อนก�น

PublicationPublication

Journal paperJournal paper Book Book Subclasses inherit all Subclasses inherit all

properties of the super classproperties of the super class

Page 43: Introduction to Object Oriented Technology

43

Hierarchy of Hierarchy of objects and objects and inheritanceinheritance Shape : x, y; area() Shape : x, y; area()

shape shape เปี7นสิ)&งที่�&ปีระกอบด�วยข�อม3ลค4อ เปี7นสิ)&งที่�&ปีระกอบด�วยข�อม3ลค4อ position positionและการและการ

ค,านวนหาพั4>นที่�& ค,านวนหาพั4>นที่�& (area)(area) circle : shape, r circle : shape, r

– a circle is a shape which also has a radius a circle is a shape which also has a radius circle inherits some information from circle inherits some information from

shape class but it should also define it shape class but it should also define it s own area routine s own area routine

single and multiple inheritance single and multiple inheritance

Page 44: Introduction to Object Oriented Technology

44

InheritanceInheritance

SQUARE

CIRCLE

SHAPE

VERTEX

drawradius

center

edgedraw

move

movexy

draw

uses

Is kind of

Is kind of

Page 45: Introduction to Object Oriented Technology

45

Separation of concept Separation of concept and implementationand implementation

Class declaration what is a Class declaration what is a circlecircle

class definition - how you class definition - how you calculate circle’s methodscalculate circle’s methods

object definition - creation object definition - creation a new circle with an ID and a new circle with an ID and at a certain position in at a certain position in spacespace

Page 46: Introduction to Object Oriented Technology

46

รถูยนต่�ม ส่ �ล�อข้0�นไป

ม พื่วงมาล�ยู่ม เก ยู่ร(ม น!�าม�นเชื่��อเพื่ล,งม แบต้เต้อร ม แบต้เต้อร ม น!�าม�นห้ล�อล��นม ไดนาโม

Page 47: Introduction to Object Oriented Technology

47

Advantages of Advantages of inheritanceinheritance Avoiding redundanciesAvoiding redundancies

– Identical code must only be Identical code must only be written oncewritten once

Reduced code sizeReduced code size Code reuseCode reuse

Page 48: Introduction to Object Oriented Technology

48

Concept of Concept of generalizationgeneralization Class: Implicitly defines a Class: Implicitly defines a

set of objectsset of objects– aCar aCar Car = Set of all cars Car = Set of all cars

Generalization: Subset Generalization: Subset relationrelation– Truck Truck Car CarCar

Truck

aFordTruck

aMercedes

classification

generalization

Page 49: Introduction to Object Oriented Technology

49

Encapsulation and Encapsulation and data hidingdata hiding

ก,าหนดว�าใครสิามารถูเห�นหร4อใช้� ก,าหนดว�าใครสิามารถูเห�นหร4อใช้� data data และ และ methods methods ของว�ต่ถู6น�>นได�ของว�ต่ถู6น�>นได�

OBJECT

method 1method 2

method 3

data 3data 2data 1

OBJECT

method 1method 2method 3

data 3data 2data 1

a. b.

Page 50: Introduction to Object Oriented Technology

50

รถุยู่นต้(

Propertiesเก1งส่ �ประต้ 1600 CCห้�วฉี ดABS ทุ��งส่ �ล�อล�อแมกซั(ส่ แดง

แอร( ว,ทุยู่�เทุป

Methods

Event บ,ดก�น แจ

ส่ต้าร(ทุ

ส่ต้าร(ทุเต้อร(ห้ม�นห้�วฉี ดจ�ายู่น!�าม�นล กส่ บทุ!างานป3� มน!�าม�นห้ล�อล��น ทุ!างานป3� มน!�าระบายู่ความร�อนทุ!างานไดนาโมจ�ายู่ไฟเข้�าแบต้เต้อร

Page 51: Introduction to Object Oriented Technology

51

PolymorphismPolymorphism หมายถู;ง ว�ต่ถู6ต่�าง ๆ ที่�&ม�ว)ธิ�การอย3�ในต่�วเหม4อน หมายถู;ง ว�ต่ถู6ต่�าง ๆ ที่�&ม�ว)ธิ�การอย3�ในต่�วเหม4อน

ก�น แต่�ว)ธิ�การกระที่,าอาจ่แต่กต่�างก�นได� ข;>นอย3� ก�น แต่�ว)ธิ�การกระที่,าอาจ่แต่กต่�างก�นได� ข;>นอย3�ก�บว�าว�ต่ถู6น�>นถู3กน,าไปีใช้�ก�บว�ต่ถู6ปีระเภที่ใดก�บว�าว�ต่ถู6น�>นถู3กน,าไปีใช้�ก�บว�ต่ถู6ปีระเภที่ใด

รถูเกDงได�ร�บการออกแบบ หร4อม�ว)ธิ�การที่�&จ่ะว)&งเร�ว รถูเกDงได�ร�บการออกแบบ หร4อม�ว)ธิ�การที่�&จ่ะว)&งเร�ว ได�ถู;ง ได�ถู;ง 200 200 ก)โลเมต่รต่�อช้�&วโมง แต่�ถู�าว)&งขณะ ก)โลเมต่รต่�อช้�&วโมง แต่�ถู�าว)&งขณะ ฝนต่ก อาจ่ว)&งเพั�ยง ฝนต่ก อาจ่ว)&งเพั�ยง 60 60 ก)โลเมต่รต่�อช้�&วโมงก)โลเมต่รต่�อช้�&วโมง

ในการเข�ยนโปีรแกรม เคร4&องพั)มพั�และจ่อภาพั ในการเข�ยนโปีรแกรม เคร4&องพั)มพั�และจ่อภาพั ต่�างก�ม�ว)ธิ�การ ต่�างก�ม�ว)ธิ�การ ((MethodMethod ) ) ที่�&ระแสิดงข�อม3ลออกที่�&ระแสิดงข�อม3ลออก

มาได�เหม4อนก�น แต่�การวางต่,าแหน�งอ�กษรบน มาได�เหม4อนก�น แต่�การวางต่,าแหน�งอ�กษรบน จ่อภาพั และที่�&กระดาษพั)มพั�อาจ่แต่กต่�างก�นได� จ่อภาพั และที่�&กระดาษพั)มพั�อาจ่แต่กต่�างก�นได�

Page 52: Introduction to Object Oriented Technology

52

PolymorphismPolymorphism““calculate area of calculate area of a circle” a circle”

““calculate area of calculate area of square”square”

Operation overloading = Operation overloading = ==ช้4&อฟ0งก�ช้�นเด�ยวก�นช้4&อฟ0งก�ช้�นเด�ยวก�น, , แต่� แต่�implementation implementation แต่กต่�างก�นแต่กต่�างก�น

In procedural languages: only In procedural languages: only for basic typesfor basic types

The same functionsshall be named alike

Page 53: Introduction to Object Oriented Technology

53

Information hidingInformation hiding Hiding of unnecessary or Hiding of unnecessary or

unimportant detailsunimportant details Access only by using Access only by using

defined operationsdefined operations

black box

Page 54: Introduction to Object Oriented Technology

54

What can be What can be “object oriented”“object oriented” Approach to user interface designApproach to user interface design

present a program as a set of objects present a program as a set of objects “one can do things to”“one can do things to”

Approach to software Approach to software developmentdevelopment

think about objects when designing think about objects when designing softwaresoftware

Approach to programmingApproach to programming build programs out of objectsbuild programs out of objects Approach to storing dataApproach to storing data store objects in object oriented store objects in object oriented

databasesdatabases Approach to integrated systemApproach to integrated system co-operative objects, interoperabilityco-operative objects, interoperability

Page 55: Introduction to Object Oriented Technology

55

OO user’s interfaceOO user’s interface Software shows objects to which Software shows objects to which

the user “can do things to”the user “can do things to” tries to create a meaningful tries to create a meaningful

hierarchy of such objectshierarchy of such objects context sensitive menuscontext sensitive menus right click buttons reveals methodsright click buttons reveals methods

Macintosh, Windows, X Windows ...Macintosh, Windows, X Windows ...

Page 56: Introduction to Object Oriented Technology

56

OO software OO software developmentdevelopment

OO design and analysisOO design and analysis cyclic developmentcyclic development support changesupport change both information and process both information and process

centred viewscentred views

ANAYSISDESIGN

EVOLUTIONMODIFICATION

Page 57: Introduction to Object Oriented Technology

57

OMG/Rational OMG/Rational ApproachApproach

Several methodologiesSeveral methodologies– Booch, Coad & Jourdon, Rumbaugh, Booch, Coad & Jourdon, Rumbaugh,

Jacobson, Martin …Jacobson, Martin …– Unified Modeling Language, Rational Unified Modeling Language, Rational

ApproachApproach Object Modeling GroupObject Modeling Group synthesis of many OO analysis and synthesis of many OO analysis and

design techniquesdesign techniques methodology and tools at methodology and tools at RationalRational

(Rational Rose) (Rational Rose)

Page 58: Introduction to Object Oriented Technology

58

Steps in the Steps in the Rational ApproachRational Approach InceptionInception– problem statement, identification problem statement, identification

of actors, identification of us of actors, identification of us e cases e cases

ElaborationElaboration– analysing problem domain, ar analysing problem domain, ar

chitectural foundation, project pan chitectural foundation, project pan ConstructionConstruction

– writing the software and the user’s writing the software and the user’s documentation documentation

TransitionTransition– installation of software, installation of software,

instructionsinstructions

Page 59: Introduction to Object Oriented Technology

59

OOD - Rational OOD - Rational RoseRose

Page 60: Introduction to Object Oriented Technology

60

Object Oriented Object Oriented DatabasesDatabases OODBMS OODBMS ค4อ ระบบการจ่�ดการก�บเก�&ยวก�บฐาน ค4อ ระบบการจ่�ดการก�บเก�&ยวก�บฐาน

ข�อม3ลในร3ปีแบบของ ข�อม3ลในร3ปีแบบของ Object Object ต่�างจ่าก ต่�างจ่าก Relational Database Relational Database

Management System (RDBMS) Management System (RDBMS) ที่�&เปี7นที่�&เปี7นระบบการจ่�ดการเก�&ยวก�บฐานข�อม3ลในร3ปีแบบของระบบการจ่�ดการเก�&ยวก�บฐานข�อม3ลในร3ปีแบบของ

ต่าราง ต่าราง (Table) (Table) และระบบฐานข�อม3ล และระบบฐานข�อม3ล RDBMS RDBMS น�>นน�>น ไม�ได�ถู3กออกแบบมาเพั4&อการเก�บข�อม3ลในล�กษณะของ ไม�ได�ถู3กออกแบบมาเพั4&อการเก�บข�อม3ลในล�กษณะของ

Object Object โดยต่รงโดยต่รง ในขณะที่�& ในขณะที่�& OODBMS OODBMS น�>นถู3กออกแบบมาสิ,าหร�บการน�>นถู3กออกแบบมาสิ,าหร�บการ

เก�บข�อม3ลในร3ปีแบบของ เก�บข�อม3ลในร3ปีแบบของ Objects Objects โดยเฉพัาะ ซ;&ง โดยเฉพัาะ ซ;&งที่,าให�ม�ปีระสิ)ที่ธิ)ภาพัในการจ่�ดเก�บข�อม3ลที่�&ม�ล�กษณะที่,าให�ม�ปีระสิ)ที่ธิ)ภาพัในการจ่�ดเก�บข�อม3ลที่�&ม�ล�กษณะ

เปี7น เปี7น Objects Objects ได�ด�กว�า ได�ด�กว�า RDBMSRDBMS

Page 61: Introduction to Object Oriented Technology

61

((((((((.) ((((((((.) pack data and methods togetherpack data and methods together implementations:implementations:

– basic : persistent objects, single basic : persistent objects, single user, one applicationuser, one application

– advanced : OO databases, multiple advanced : OO databases, multiple concurrent users, versioning, concurrent users, versioning, access control, multiple access control, multiple applicationsapplications

– distributed objects : objects distributed objects : objects distributed over several machines distributed over several machines on the network such as Internet or on the network such as Internet or intranetintranet

several available commerciallyseveral available commercially

Page 62: Introduction to Object Oriented Technology

62

OO Databases OO Databases (cont.)(cont.)

OO databases well suited OO databases well suited for engineering and for engineering and technical usestechnical uses– many different concepts of many different concepts of

data types, not so many data types, not so many instancesinstances

– business applications: the business applications: the appositeapposite

several commercial vendorsseveral commercial vendors

Page 63: Introduction to Object Oriented Technology

63

OO ProgrammingOO Programming หมายถู;ง การพั�ฒนาโปีรแกรมที่�&ใช้�ว�ต่ถู6

เปี7นเคร4&องม4อ (Tools) โดยที่�&ว�ต่ถู6น�>น ต่�องม�ล�กษณะพั4>นฐาน 3 ปีระการ ด�งน�>• เอนแคพัซ6เลช้�น

(Encapsulation)

• อ)นเฮอร)แที่นซ�(Inheritance)

• โพัล)มอฟGสิซ;ม(Polimophism)

Page 64: Introduction to Object Oriented Technology

64

OO LanguagesOO Languages ModelingModeling

– UMLUML ImplementationImplementation

– C++ , Java, Smalltalk C++ , Java, Smalltalk– many other languages with OO many other languages with OO

features features– Visual Basic , Cobol, FORTRAN, Perl Visual Basic , Cobol, FORTRAN, Perl

…… C++C++

– compiled language, fast, powerful compiled language, fast, powerful and dangerous and dangerous– multiple inheritance, templates .. multiple inheritance, templates ..– quite portable quite portable

JavaJava– interpreted language, slower, safer interpreted language, slower, safer– 100% portable, Java virtual machine 100% portable, Java virtual machine

Page 65: Introduction to Object Oriented Technology

65

Sample C++ CodeSample C++ Code# include <stream.hpp>class Complex{ private : float re, im; public : Complex (float r= 0, float i=0) : re(r), im(i) { } Complex operator + (Complex &); operator float ( ) { return re ; } ; friend ostream& operator << (ostream &os, Complex &c);} ;//definitions follow

Page 66: Introduction to Object Oriented Technology

66

Sample Java CodeSample Java Codeimport java.awt.Graphics;

class Hello1 extends java.applet.Applet{ public void paint(Graphics g) { g.drawString ( “Hello, World!!!\n\n”, 50, 25 ) ; }}

Page 67: Introduction to Object Oriented Technology

67

OO Programming OO Programming Environments - Class Environments - Class

BrowsersBrowsers

Page 68: Introduction to Object Oriented Technology

68

Object oriented Object oriented integrated integrated

environmentsenvironments Normally, objects and classes defined Normally, objects and classes defined in one program, cannot be used in in one program, cannot be used in another;another;– e.g. a beam object, as built into an e.g. a beam object, as built into an

structural engineering application, structural engineering application, cannot be used in a CAD drafting cannot be used in a CAD drafting packagepackage

alternative solutionsalternative solutions– class librariesclass libraries : : build all applications on build all applications on

top of the same model and resulting top of the same model and resulting class library and exchange data in class library and exchange data in standard formats; the STEP and IAI standard formats; the STEP and IAI reality ; efficient, compile time bindingreality ; efficient, compile time binding

– software interoperabilitysoftware interoperability : : exchange full exchange full objects, not just the data (IAI promise); objects, not just the data (IAI promise); more flexible, component based more flexible, component based software; late bindingsoftware; late binding

Page 69: Introduction to Object Oriented Technology

69

Interoperability Vs. Interoperability Vs. data exchangedata exchangeapplication A application B

Data exchange

message

reply

Page 70: Introduction to Object Oriented Technology

70

Component based Component based softwaresoftware Some examples of components : Some examples of components :

– “ “ graph” graph” เปี7นเปี7นobjectobjectที่�&สิามารถูใช้�ในที่�&สิามารถูใช้�ใน โปีรแกรมเช้�น โปีรแกรมเช้�น Word, Excel, PowerPoint Word, Excel, PowerPoint

– ““ textbox” textbox” เปี7น เปี7น object object สิามารถูใช้�ได�ในสิามารถูใช้�ได�ใน โปีรแกรมที่�&วไปีเช้�นแบบ โปีรแกรมที่�&วไปีเช้�นแบบ formsforms

– เราไม�จ่,าเปี7นต่�อง เราไม�จ่,าเปี7นต่�อง run run โปีรแกม โปีรแกม Word Word เพั4&อใช้� เพั4&อใช้� spelling checker spelling checker

component = object whose component = object whose public properties are seen after public properties are seen after

compilationcompilation– components components จ่ะร3�จ่�ก จ่ะร3�จ่�ก datadata และ และ function function

ที่�&ก,าหนดไว�ในที่�&ก,าหนดไว�ใน standard standard librarylibrary– data data และ และ functional functional สิามารถูเข�าถู;งโดยสิามารถูเข�าถู;งโดย

มาต่ราฐานที่�&ก,าหนดมาต่ราฐานที่�&ก,าหนด– language independent language independent– use network to transport use network to transport

messagesmessages

Page 71: Introduction to Object Oriented Technology

71

StandardsStandards Two competing standard ways of Two competing standard ways of

exporting objectsexporting objects– CORBACORBA (Object Management Group )(Object Management Group )– DCOMDCOM (Microsoft)(Microsoft)

CORBA = Common Object CORBA = Common Object Request Broker ArchitectureRequest Broker Architecture

DCOM = Distributed Component DCOM = Distributed Component Object ModelObject Model

Page 72: Introduction to Object Oriented Technology

72

Example of Object Example of Object Request Broker Request Broker

ArchitectureArchitecturedocument browserdocument browser

Process wizardProcess wizard

Product browserProduct browser

......

SofiCADSofiCADSoFiSTiKSoFiSTiK

PAULAPAULASoFiPLUSSoFiPLUS

GWMGWMCuFIMSCuFIMS

......

E-mailE-mailweb browserweb browser

ORBIL toolkit

...concad

InternetEXPRESSCommon

RequestBroker

Regulation Broker

Document Server

...

Product Mgmt Server

Process Mgmt ServerProduct ModelsProduct Models

Process ModelsProcess Models

Document M.Document M.

Regulation MRegulation M

Client applicat

ion layer

adapter layer

Information

logisticservices

Serverplug-inlayer

projectdata

Other

data

Page 73: Introduction to Object Oriented Technology

73

SummarySummary Object Orientation Object Orientation ม�ปีระโยช้น�ในการม�ปีระโยช้น�ในการ

แก�ปี0ญหาเช้)งว)ศวกรรมแก�ปี0ญหาเช้)งว)ศวกรรม จ่�ดการที่6กสิ)&งใน จ่�ดการที่6กสิ)&งใน real real world world ให�อย3�ในร3ปีของให�อย3�ในร3ปีของ

ว�ต่ถู6ซ;&งปีระกอบด�วย ว�ต่ถู6ซ;&งปีระกอบด�วย data data และและ methods, methods, จ่�ดกล6�มว�ต่ถู6ที่�&เหม4อนก�นเปี7น จ่�ดกล6�มว�ต่ถู6ที่�&เหม4อนก�นเปี7น classes classes และม�และม�

โครงสิร�างเปี7นแบบ โครงสิร�างเปี7นแบบ hierarchieshierarchies Object orientation Object orientation สิน�บสิน6นการสิน�บสิน6นการ

ออกแบบและเที่คน)คการว)เคราะห�ออกแบบและเที่คน)คการว)เคราะห� , , ภาษาที่�&ใช้�ภาษาที่�&ใช้�เข�ยนโปีรแกรมเข�ยนโปีรแกรม , , ระบบฐานข�อม3ล และ ระบบฐานข�อม3ล และ

integration architectures integration architectures สิ,าหร�บใช้�สิ,าหร�บใช้�ในเคร4อข�ายอ)นเที่อร�เน�ต่ในเคร4อข�ายอ)นเที่อร�เน�ต่