Introduction z Objectoriented design z Unified Modeling Language
Introduction z. Object-oriented design. z. Unified Modeling Language (UML). © 2000 Morgan Kaufman Overheads for Computers as Components
System modeling z. Need languages to describe systems: yuseful across several levels of abstraction; yunderstandable within and between organizations. z. Block diagrams are a start, but don’t cover everything. © 2000 Morgan Kaufman Overheads for Computers as Components
Object-oriented design z. Object-oriented (OO) design: A generalization of object-oriented programming. z. Object = state + methods. y. State provides each object with its own identity. y. Methods provide an abstract interface to the object. © 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; } } © 2000 Morgan Kaufman Overheads for Computers as Components
OO implementation in C typedef struct { pixels: pixeltype[IMAX, JMAX]; } display; display d 1; pixeltype pixelval(pixel *px, int i, int j) { return px[i, j]; } © 2000 Morgan Kaufman Overheads for Computers as Components
Objects and classes z. Class: object type. z. Class defines the object’s state elements but state values may change over time. z. Class defines the methods used to interact with all objects of that type. y. Each object has its own state. © 2000 Morgan Kaufman Overheads for Computers as Components
OO design principles z. Some objects will closely correspond to real-world objects. y. Some objects may be useful only for description or implementation. z. Objects provide interfaces to read/write state, hiding the object’s implementation from the rest of the system. © 2000 Morgan Kaufman Overheads for Computers as Components
UML z. Developed by Booch et al. z. Goals: yobject-oriented; yvisual; yuseful at many levels of abstraction; yusable for all aspects of design. © 2000 Morgan Kaufman Overheads for Computers as Components
UML object name class name d 1: Display pixels is a 2 -D array pixels: array[] of pixels elements menu_items comment attributes © 2000 Morgan Kaufman Overheads for Computers as Components
UML class Display class name pixels elements menu_items mouse_click() draw_box © 2000 Morgan Kaufman Overheads for Computers as Components operations
The class interface z. The operations provide the abstract interface between the class’s implementation and other classes. z. Operations may have arguments, return values. z. An operation can examine and/or modify the object’s state. © 2000 Morgan Kaufman Overheads for Computers as Components
Choose your interface properly z. If the interface is too small/specialized: yobject is hard to use for even one application; yeven harder to reuse. z. If the interface is too large: yclass becomes too cumbersome for designers to understand; yimplementation may be too slow; y spec and implementation probably buggy. © 2000 Morgan Overheads for Computersare as Kaufman Components
Relationships between objects and classes z. Association: objects communicate but one does not own the other. z. Aggregation: a complex object is made of several smaller objects. z. Composition: aggregation in which owner does not allow access to its components. z. Generalization: define one class in terms of another. © 2000 Morgan Kaufman Overheads for Computers as Components
Class derivation z. May want to define one class in terms of another. y. Derived class inherits attributes, operations of base class. Derived_class Base_class © 2000 Morgan Kaufman Overheads for Computers as Components UML generalization
Class derivation example Display base class pixels elements menu_items derived class BW_display © 2000 Morgan Kaufman pixel() set_pixel() mouse_click() draw_box Color_map_display Overheads for Computers as Components
Multiple inheritance base classes Speaker Display Multimedia_display derived class © 2000 Morgan Kaufman Overheads for Computers as Components
Links and associations z. Link: describes relationships between objects. z. Association: describes relationship between classes. © 2000 Morgan Kaufman Overheads for Computers as Components
Link example z. Link defines the contains relationship: message msg = msg 1 length = 1102 message set count = 2 message msg = msg 2 length = 2114 © 2000 Morgan Kaufman Overheads for Computers as Components
Association example # containing message sets # contained messages message 0. . * msg: ADPCM_stream length : integer © 2000 Morgan Kaufman 1 contains Overheads for Computers as Components message set count : integer
Stereotypes z. Stereotype: recurring combination of elements in an object or class. z. Example: y<<foo>> © 2000 Morgan Kaufman Overheads for Computers as Components
Behavioral description z. Several ways to describe behavior: yinternal view; yexternal view. © 2000 Morgan Kaufman Overheads for Computers as Components
State machines transition a state © 2000 Morgan Kaufman b state name Overheads for Computers as Components
Event-driven state machines z. Behavioral descriptions are written as event-driven state machines. y. Machine changes state when receiving an input. z. An event may come from inside or outside of the system. © 2000 Morgan Kaufman Overheads for Computers as Components
Types of events z. Signal: asynchronous event. z. Call: synchronized communication. z. Timer: activated by time. © 2000 Morgan Kaufman Overheads for Computers as Components
Signal event <<signal>> mouse_click leftorright: button x, y: position a mouse_click(x, y, button) b declaration event description © 2000 Morgan Kaufman Overheads for Computers as Components
Call event draw_box(10, 5, 3, 2, blue) c © 2000 Morgan Kaufman d Overheads for Computers as Components
Timer event tm(time-value) e © 2000 Morgan Kaufman f Overheads for Computers as Components
Example state machine start input/output mouse_click(x, y, button)/ region = menu/ which_menu(i) find_region(region) region found region = drawing/ find_object(objid) called menu item highlight(objid) found object © 2000 Morgan Kaufman got menu item call_menu(I) object highlighted Overheads for Computers as Components finish
Sequence diagram z. Shows sequence of operations over time. z. Relates behaviors of multiple objects. © 2000 Morgan Kaufman Overheads for Computers as Components
Sequence diagram example m: Mouse d 1: Display mouse_click(x, y, button) which_menu(x, y, i) time call_menu(i) © 2000 Morgan Kaufman Overheads for Computers as Components u: Menu
Summary z. Object-oriented design helps us organize a design. z. UML is a transportable system design language. y. Provides structural and behavioral description primitives. © 2000 Morgan Kaufman Overheads for Computers as Components
- Slides: 31