Introduction zObject-oriented design. zUnified Modeling Language (UML). 1 © 2010 Husam Alzaq 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. 2 © 2010 Husam Alzaq 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. 3 © 2010 Husam Alzaq 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. 4 © 2010 Husam Alzaq 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. 5 © 2010 Husam Alzaq 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. 6 © 2010 Husam Alzaq 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 7 © 2010 Husam Alzaq Computers as Components
UML class Display pixels elements menu_items mouse_click() draw_box operationsclass name 8 © 2010 Husam Alzaq 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. 9 © 2010 Husam Alzaq 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. 10 © 2010 Husam Alzaq 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. 11 © 2010 Husam Alzaq 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 12 © 2010 Husam Alzaq 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 13 © 2010 Husam Alzaq Computers as Components
Multiple inheritance SpeakerDisplay Multimedia_display base classes derived class 14 © 2010 Husam Alzaq Computers as Components
Links and associations zLink: describes relationships between objects. zAssociation: describes relationship between classes. 15 © 2010 Husam Alzaq Computers as Components
Link example zLink defines the contains relationship: message msg = msg1 length = 1102 message msg = msg2 length = 2114 message set count = 2 16 © 2010 Husam Alzaq Computers as Components
Association example message msg: ADPCM_stream length : integer message set count : integer 0..*1 contains # contained messages # containing message sets 17 © 2010 Husam Alzaq Computers as Components
Stereotypes zStereotype: recurring combination of elements in an object or class. zExample: y > 18 © 2010 Husam Alzaq Computers as Components
Behavioral description zSeveral ways to describe behavior: yinternal view; yexternal view. 19 © 2010 Husam Alzaq Computers as Components
State machines ab state state name transition 20 © 2010 Husam Alzaq 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. 21 © 2010 Husam Alzaq Computers as Components
Types of events zSignal: asynchronous event. zCall: synchronized communication. zTimer: activated by time. 22 © 2010 Husam Alzaq Computers as Components
Signal event > mouse_click leftorright: button x, y: position declaration a b mouse_click(x,y,button) event description 23 © 2010 Husam Alzaq Computers as Components
Call event cd draw_box(10,5,3,2,blue) 24 © 2010 Husam Alzaq Computers as Components
Timer event ef tm(time-value) 25 © 2010 Husam Alzaq 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) 26 © 2010 Husam Alzaq Computers as Components
Sequence diagram zShows sequence of operations over time. zRelates behaviors of multiple objects. 27 © 2010 Husam Alzaq Computers as Components
Sequence diagram example m: Moused1: Displayu: Menu mouse_click(x,y,button) which_menu(x,y,i) call_menu(i) time 28 © 2010 Husam Alzaq 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. 29 © 2010 Husam Alzaq Computers as Components