1 / 31

Introduction

An introduction to object-oriented design principles and the Unified Modeling Language (UML) for system modeling. Covers topics such as classes, interfaces, relationships, and behavioral descriptions. Suitable for understanding and describing systems at different levels of abstraction.

hpineda
Télécharger la présentation

Introduction

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Introduction • Object-oriented design. • Unified Modeling Language (UML). Overheads for Computers as Components

  2. System modeling • Need languages to describe systems: • useful across several levels of abstraction; • understandable within and between organizations. • Block diagrams are a start, but don’t cover everything. Overheads for Computers as Components

  3. Object-oriented design • Object-oriented (OO) design: A generalization of object-oriented programming. • Object = state + methods. • State provides each object with its own identity. • Methods provide an abstract interface to the object. Overheads for Computers as Components

  4. 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; } } Overheads for Computers as Components

  5. 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]; } Overheads for Computers as Components

  6. Objects and classes • Class: object type. • Class defines the object’s state elements but state values may change over time. • Class defines the methods used to interact with all objects of that type. • Each object has its own state. Overheads for Computers as Components

  7. OO design principles • Some objects will closely correspond to real-world objects. • Some objects may be useful only for description or implementation. • Objects provide interfaces to read/write state, hiding the object’s implementation from the rest of the system. Overheads for Computers as Components

  8. UML • Developed by Booch et al. • Goals: • object-oriented; • visual; • useful at many levels of abstraction; • usable for all aspects of design. Overheads for Computers as Components

  9. object name class name comment attributes UML object d1: Display pixels is a 2-D array pixels: array[] of pixels elements menu_items Overheads for Computers as Components

  10. class name operations UML class Display pixels elements menu_items mouse_click() draw_box Overheads for Computers as Components

  11. The class interface • The operations provide the abstract interface between the class’s implementation and other classes. • Operations may have arguments, return values. • An operation can examine and/or modify the object’s state. Overheads for Computers as Components

  12. Choose your interface properly • If the interface is too small/specialized: • object is hard to use for even one application; • even harder to reuse. • If the interface is too large: • class becomes too cumbersome for designers to understand; • implementation may be too slow; • spec and implementation are probably buggy. Overheads for Computers as Components

  13. Relationships between objects and classes • Association: objects communicate but one does not own the other. • Aggregation: a complex object is made of several smaller objects. • Composition: aggregation in which owner does not allow access to its components. • Generalization: define one class in terms of another. Overheads for Computers as Components

  14. UML generalization Class derivation • May want to define one class in terms of another. • Derived class inherits attributes, operations of base class. Derived_class Base_class Overheads for Computers as Components

  15. base class Class derivation example Display pixels elements menu_items pixel() set_pixel() mouse_click() draw_box derived class BW_display Color_map_display Overheads for Computers as Components

  16. base classes derived class Multiple inheritance Speaker Display Multimedia_display Overheads for Computers as Components

  17. Links and associations • Link: describes relationships between objects. • Association: describes relationship between classes. Overheads for Computers as Components

  18. Link example • Link defines the contains relationship: message msg = msg1 length = 1102 message set count = 2 message msg = msg2 length = 2114 Overheads for Computers as Components

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

  20. Stereotypes • Stereotype: recurring combination of elements in an object or class. • Example: • <<foo>> Overheads for Computers as Components

  21. Behavioral description • Several ways to describe behavior: • internal view; • external view. Overheads for Computers as Components

  22. transition state state name State machines a b Overheads for Computers as Components

  23. Event-driven state machines • Behavioral descriptions are written as event-driven state machines. • Machine changes state when receiving an input. • An event may come from inside or outside of the system. Overheads for Computers as Components

  24. Types of events • Signal: asynchronous event. • Call: synchronized communication. • Timer: activated by time. Overheads for Computers as Components

  25. Signal event <<signal>> mouse_click a leftorright: button x, y: position mouse_click(x,y,button) b declaration event description Overheads for Computers as Components

  26. Call event draw_box(10,5,3,2,blue) c d Overheads for Computers as Components

  27. Timer event tm(time-value) e f Overheads for Computers as Components

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

  29. Sequence diagram • Shows sequence of operations over time. • Relates behaviors of multiple objects. Overheads for Computers as Components

  30. Sequence diagram example m: Mouse d1: Display u: Menu mouse_click(x,y,button) which_menu(x,y,i) time call_menu(i) Overheads for Computers as Components

  31. Summary • Object-oriented design helps us organize a design. • UML is a transportable system design language. • Provides structural and behavioral description primitives. Overheads for Computers as Components

More Related