Presentation is loading. Please wait.

Presentation is loading. Please wait.

© 2000 Morgan Kaufman Overheads for Computers as Components Introduction zObject-oriented design. zUnified Modeling Language (UML).

Similar presentations


Presentation on theme: "© 2000 Morgan Kaufman Overheads for Computers as Components Introduction zObject-oriented design. zUnified Modeling Language (UML)."— Presentation transcript:

1

2 © 2000 Morgan Kaufman Overheads for Computers as Components Introduction zObject-oriented design. zUnified Modeling Language (UML).

3 © 2000 Morgan Kaufman Overheads for Computers as Components System modeling zNeed languages to describe systems: yuseful across several levels of abstraction; yunderstandable within and between organizations. zBlock diagrams are a start, but don’t cover everything.

4 © 2000 Morgan Kaufman Overheads for Computers as Components Object-oriented design zObject-oriented (OO) design: A generalization of object-oriented programming. zObject = state + methods. yState provides each object with its own identity. yMethods provide an abstract interface to the object.

5 © 2000 Morgan Kaufman Overheads for Computers as Components OO implementation in C++ class display { pixels : pixeltype[IMAX,JMAX]; public: display() { } pixeltype pixel(int i, int j) { return pixels[i,j]; } void set_pixel(pixeltype val, int i, int j) { pixels[i,j] = val; } }

6 © 2000 Morgan Kaufman Overheads for Computers as Components OO implementation in C typedef struct { pixels: pixeltype[IMAX,JMAX]; } display; display d1; pixeltype pixelval(pixel *px, int i, int j) { return px[i,j]; }

7 © 2000 Morgan Kaufman Overheads for Computers as Components Objects and classes zClass: object type. zClass defines the object’s state elements but state values may change over time. zClass defines the methods used to interact with all objects of that type. yEach object has its own state.

8 © 2000 Morgan Kaufman Overheads for Computers as Components OO design principles zSome objects will closely correspond to real-world objects. ySome objects may be useful only for description or implementation. zObjects provide interfaces to read/write state, hiding the object’s implementation from the rest of the system.

9 © 2000 Morgan Kaufman Overheads for Computers as Components UML zDeveloped by Booch et al. zGoals: yobject-oriented; yvisual; yuseful at many levels of abstraction; yusable for all aspects of design.

10 © 2000 Morgan Kaufman Overheads for Computers as Components UML object d1: Display pixels: array[] of pixels elements menu_items pixels is a 2-D array comment object name class name attributes

11 © 2000 Morgan Kaufman Overheads for Computers as Components UML class Display pixels elements menu_items mouse_click() draw_box operationsclass name

12 © 2000 Morgan Kaufman Overheads for Computers as Components The class interface zThe operations provide the abstract interface between the class’s implementation and other classes. zOperations may have arguments, return values. zAn operation can examine and/or modify the object’s state.

13 © 2000 Morgan Kaufman Overheads for Computers as Components Choose your interface properly zIf the interface is too small/specialized: yobject is hard to use for even one application; yeven harder to reuse. zIf the interface is too large: yclass becomes too cumbersome for designers to understand; yimplementation may be too slow; yspec and implementation are probably buggy.

14 © 2000 Morgan Kaufman Overheads for Computers as Components Relationships between objects and classes zAssociation: objects communicate but one does not own the other. zAggregation: a complex object is made of several smaller objects. zComposition: aggregation in which owner does not allow access to its components. zGeneralization: define one class in terms of another.

15 © 2000 Morgan Kaufman Overheads for Computers as Components Class derivation zMay want to define one class in terms of another. yDerived class inherits attributes, operations of base class. Derived_class Base_class UML generalization

16 © 2000 Morgan Kaufman Overheads for Computers as Components Class derivation example Display pixels elements menu_items pixel() set_pixel() mouse_click() draw_box BW_displayColor_map_display base class derived class

17 © 2000 Morgan Kaufman Overheads for Computers as Components Multiple inheritance SpeakerDisplay Multimedia_display base classes derived class

18 © 2000 Morgan Kaufman Overheads for Computers as Components Links and associations zLink: describes relationships between objects. zAssociation: describes relationship between classes.

19 © 2000 Morgan Kaufman Overheads for Computers as Components Link example zLink defines the contains relationship: message msg = msg1 length = 1102 message msg = msg2 length = 2114 message set count = 2

20 © 2000 Morgan Kaufman Overheads for Computers as Components Association example message msg: ADPCM_stream length : integer message set count : integer 0..*1 contains # contained messages # containing message sets

21 © 2000 Morgan Kaufman Overheads for Computers as Components Stereotypes zStereotype: recurring combination of elements in an object or class. zExample: y >

22 © 2000 Morgan Kaufman Overheads for Computers as Components Behavioral description zSeveral ways to describe behavior: yinternal view; yexternal view.

23 © 2000 Morgan Kaufman Overheads for Computers as Components State machines ab state state name transition

24 © 2000 Morgan Kaufman Overheads for Computers as Components Event-driven state machines zBehavioral descriptions are written as event-driven state machines. yMachine changes state when receiving an input. zAn event may come from inside or outside of the system.

25 © 2000 Morgan Kaufman Overheads for Computers as Components Types of events zSignal: asynchronous event. zCall: synchronized communication. zTimer: activated by time.

26 © 2000 Morgan Kaufman Overheads for Computers as Components Signal event > mouse_click leftorright: button x, y: position declaration a b mouse_click(x,y,button) event description

27 © 2000 Morgan Kaufman Overheads for Computers as Components Call event cd draw_box(10,5,3,2,blue)

28 © 2000 Morgan Kaufman Overheads for Computers as Components Timer event ef tm(time-value)

29 © 2000 Morgan Kaufman Overheads for Computers as Components Example state machine region found got menu item called menu item found object highlighted start finish mouse_click(x,y,button)/ find_region(region) input/output region = menu/ which_menu(i) call_menu(I) region = drawing/ find_object(objid) highlight(objid)

30 © 2000 Morgan Kaufman Overheads for Computers as Components Sequence diagram zShows sequence of operations over time. zRelates behaviors of multiple objects.

31 © 2000 Morgan Kaufman Overheads for Computers as Components Sequence diagram example m: Moused1: Displayu: Menu mouse_click(x,y,button) which_menu(x,y,i) call_menu(i) time

32 © 2000 Morgan Kaufman Overheads for Computers as Components Summary zObject-oriented design helps us organize a design. zUML is a transportable system design language. yProvides structural and behavioral description primitives.


Download ppt "© 2000 Morgan Kaufman Overheads for Computers as Components Introduction zObject-oriented design. zUnified Modeling Language (UML)."

Similar presentations


Ads by Google