1 / 97

Chapter 2 UML Overview

Chapter 2 UML Overview. Building blocks of the UML Structure things in the UML Behavioral things in the UML Grouping things in the UML Relationships in the UML Diagrams in the UML Extension mechanism of the UML Simple Example - Hello World. Building Blocks of the UML.

marcena
Télécharger la présentation

Chapter 2 UML Overview

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. Chapter 2 UML Overview • Building blocks of the UML • Structure things in the UML • Behavioral things in the UML • Grouping things in the UML • Relationships in the UML • Diagrams in the UML • Extension mechanism of the UML • Simple Example - Hello World

  2. Building Blocks of the UML

  3. Building Blocks of the UML • The vocabulary of the UML encompasses three kinds of building blocks: • Things: the abstractions that are first-class citizens in a model; • Relationships: relationships tie these things together; • Diagrams: diagrams group interesting collections of things.

  4. Things in the UML • There are four kinds of things in the UML: • Structural things: class, interface, collaboration, use case, active class, component, artifact & node • Behavioral things: interaction, state machine, activity • Grouping things: package • Annotational things: note • These things are the basic object-oriented building blocks of the UML.

  5. Structural things in the UML

  6. Structural things in the UML • the nouns of UML models. • the mostly static parts of a model, either conceptual or physical • Collectively, the structural things are called classifiers • eight kinds: • Logic view: class, interface, collaboration, • Requirement view:use case • Process view: active class • Implementation view: component, artifact, node

  7. Objects Professor Smith Professor Mellon Professor Jones Structural things - Class • A class is a description of a set of objects that share the same attributes, operations, relationships, and semantics. • A class is represented using a compartmented rectangle Attributes Operations

  8. Class Name Professor name Attributes empID Operations create( ) save( ) delete( ) change( ) Review: Class Compartments • A class is comprised of three sections • The first section contains the class name • The second section shows the structure (attributes) • The third section shows the behavior (operations)

  9. a + b = 10 Professor Clark Review: Representing Objects • An object is represented as rectangles with underlined names : Professor ProfessorClark Class Name Only ProfessorClark : Professor Object Name Only Class and Object Name

  10. Pyramid Cube Tube <<interface>> Shape Draw Move Scale Rotate Structural things - Interface • An interfaceis a collection of operations that specify a service of a class or component. • Interfaces support “plug-and-play” architectures Realization relationship

  11. Pyramid Pyramid Cube Tube Tube Cube <<interface>> Shape Draw Move Scale Rotate Review: Interface Representations Elided/Iconic Representation(“lollipop”) Shape Canonical (Class/Stereotype) Representation

  12. Structural things - Collaboration • In the context of a system's architecture, a collaboration allows you to name a conceptual chunk that encompasses both static and dynamic aspects. • A collaboration names a society of classes, interfaces, and other elements that work together to provide some cooperative behavior that's bigger than the sum of all its parts. • You use collaborations to specify the realization of use cases and operations, and to model the architecturally significant mechanisms of your system.

  13. Structural things - Collaboration • A collaboration is a society of classes, interfaces, and other elements that work together to provide some cooperative behavior that's bigger than the sum of all its parts. • A collaboration is also the specification of how an element, such as a classifier (including a class, interface,component, node, or use case) or an operation, is realized by a set of classifiers and associations playing specific roles used in a specific way. • Graphically, a collaboration is rendered as an ellipse with dashed lines. Login Login

  14. Structural things – Use Case • a use case is a description of set of sequence of actions that a system performs that yields an observable result of value to a particular actor. • A use case is used to structure the behavioral things in a model. • A use case is realized by a collaboration. • Graphically, a use case is rendered as an ellipse with solid lines, usually including only its name. Login Login

  15. EventManager suspend() flush() Structural things – Active Class • an active class is a class whose objects own one or more processes or threads and therefore can initiate control activity. • An active class is just like a class except that its objects represent elements whose behavior is concurrent with other elements. • Graphically, an active class is rendered as a class with double lines on the left and right; it usually includes its name, attributes, and operations.

  16. Orderform Structural things – Component • A component is a modular physical part of the system design that hides its implementation behind a set of external interfaces. • The implementation of a component can be expressed by wiring together parts and connectors. • Graphically, a component is rendered like a class with a special icon in the upper right corner.

  17. Structural things – Artifact • An artifact is a physical and replaceable part of a system that contains physical information ("bits"). • An artifact typically represents the physical packaging of source or run-time information. • Graphically, an artifact is rendered as a rectangle with the keyword «artifact» above the name. <<artifact>> Login.dll

  18. <<Node>> Node #1 Structural things – Node • a node is a physical element that exists at run time and represents a computational resource, generally having at least some memory and, often, processing capability. • A set of components may reside on a node and may also migrate from node to node. • Graphically, a node is rendered as a cube, usually including only its name.

  19. Behavioral things in the UML

  20. Behavioral things in the UML • the verbs of UML models. • the mostly dynamic parts of a model • three primary kinds: • Among a set of objects: interaction • For an object: state machine • The sequence of steps: activity

  21. display() Behavioral things - Interaction • an interaction is a behavior that comprises a set of messages exchanged among a set of objects within a particular context to accomplish a specific purpose. • The behavior of a society of objects or of an individual operation may be specified with an interaction. • An interaction involves a number of other elements, including messages, action sequences (the behavior invoked by a message), and links (the connection between objects). • Graphically, a message is rendered as a directed line, almost always including the name of its operation.

  22. Collaboration Diagrams Sequence Diagrams What Is an Interaction Diagram? • An interaction diagram shows an interaction, consisting of a set of objects and their relationships, including the messages that may be dispatched among them. • It models the dynamic aspects of a system.

  23. Sequence Diagrams What Is a Sequence Diagram? • A sequence diagram is an interaction diagram that emphasizes the time ordering of messages. • The diagram shows • The objects participating in the interaction. • The sequence of messages exchanged.

  24. What Is a Communication Diagram? • A communication diagram emphasizes the organization of the objects that participate in an interaction. • The communication diagram shows • The objects participating in the interaction. • Links between the objects. • Messages passed between the objects. Communication Diagrams

  25. Interaction Diagram Example - HelloWorldApp2.java public class HelloWorldApp2 { public static void main(String[] args) { Greeting hello = new Greeting(); hello.greet("Hello World"); } } class Greeting { public void greet(String s) { System.out.println(s); } }

  26. Behavioral things - State machine • a state machine is a behavior that specifies the sequences of states an object or an interaction goes through during its lifetime in response to events, together with its responses to those events. • The behavior of an individual class or a collaboration of classes may be specified with a state machine. • A state machine involves a number of other elements, including states, transitions, events, and activities. • Graphically, a state is rendered as a rounded rectangle, usually including its name and its substates, if any. waiting

  27. Behavioral things - Activity • an activity is a behavior that specifies the sequence of steps a computational process performs • In an activity, the focus is on the flows among steps without regard to which object performs each step. • A step of an activity is called an action. • Graphically, an action is rendered as a rounded rectangle with a name indicating its purpose. States and actions are distinguished by their different contexts. waiting

  28. Grouping things in the UML

  29. Grouping things in the UML • A package is a general-purpose mechanism for organizing elements into groups. • In all, there is one primary kind of grouping thing, namely, packages. • Packages are the basic grouping things with which you may organize a UML model. There are also variations, such as frameworks, models, and subsystems (kinds of packages)

  30. PackageA PackageB A(from packageA) B(from packageB) Grouping things - Package • Grouping things are the organizational parts of UML models. • Structural things, behavioral things, and even other grouping things may be placed in a package. • Unlike components (which exist at run time), a package is purely conceptual (meaning that it exists only at development time). • Graphically, a package is rendered as a tabbed folder, usually including only its name and, sometimes, its contents. Dependency relationship

  31. One of these is executed: Annotational things - Note • Annotational things are the explanatory parts of UML models. • These are the comments you may apply to describe, illuminate, and remark about any element in a model. • There is one primary kind of annotational thing, called a note. • A note is simply a symbol for rendering constraints and comments attached to an element or a collection of elements. • Graphically, a note is rendered as a rectangle with a dog-eared corner, together with a textual or graphical comment.

  32. Relationships in the UML

  33. Window + open() : void + close() : void + handleEvent(e: Event) : void <<Interface>> AbstractWindow Event + open() : void + close() : void ConsoleWindow DialogBox Control Relationships in the UML • There are four kinds of relationships in the UML: • Association • Dependency • Generalization • Realization

  34. <<entity>> <<entity>> <<entity>> Student Schedule Course Professor University Association Name Role Names Works for Employee Employer Association What Is an Association? • The semantic relationship between two or more classes that specifies connections among their instances • A structural relationship, specifying that objects of one thing are connected to objects of another

  35. class CatalogueEntry { private string name; private int number; private double cost; publicdouble getCost () { return cost; } } class Part {privateCatalogueEntry entry; public double cost () {return entry.getCost();}} CatalogueEntry screw= new CatalogueEntry (“screw”, 28834, 0.02);Partscrew1 = new Part(screw) ; screw1.cost(); What Is an Association? – A example

  36. : CatalogueEntry : CatalogueEntry name = “screw” name = “screw” number = 28834 number = 28834 cost = 0.02 cost = 0.02 Describes Describes : Part : Part Fig. Links between objects getCost() cost() Client : Part Fig. Finding the cost of a Part What Is an Association? – A example • An association is a structual relationship that desribes a set of links. • a link being a connection among objects. • A link specifies a path along which one object can dispatch a message to another (or the same)object.

  37. CatalogueEntry Part - name - number + getCost() - cost 1 * + cost() Fig. Example of an association What Is an Association? – A example • In general, a link is an instance of an association.

  38. ‘ Schedule.cls Public theStudent as Student Schedule ‘ Student.cls Public theSchedule as Schedule Student Example : Associations mapping to VB 1 1

  39. job n n n n Person Company -employee -employer AssociationName Role Names Adornments that apply to associations. • An association name: to describe the nature of the relationship. • When a class participates in an association, it has a specific role that it plays in that relationship. A role is just the face the class at the near end of the association presents to the class at the other end of the association.

  40. 1 Multiplicity * 0..* 1..* 1 0..* 0..1 2..4 2, 4..6 University Professor Navigation Adornments that apply to associations. • The multiplicity of an association's role: to state how many objects may be connected across an instance of an association. • Navigation: Given a plain, unadorned association between two classes, it's possible to navigate from objects of one kind to objects of the other kind. • Unspecified • Exactly one • Zero or more (many, unlimited) • One or more • Zero or one • Specified range • Multiple, disjoint ranges

  41. Student Schedule Association - Aggregation • A special form of association that models a whole-part relationship between an aggregate (the whole) and its parts Whole Part Aggregation

  42. Student Schedule Association - Composition • A form of aggregation with strong ownership and coincident lifetimes • The parts cannot survive the whole/aggregate Part Whole Composition

  43. 1..* * -employer -employee Company Person Job -salary + getSalary() Association - Association Class • In an association between two classes, the association itself might have properties. • A class “attached” to an association • Contains properties of a relationship • One instance per link

  44. 1..* * -employer -employee Company Person Company Person Job Job 1 1..* * 1 -salary -salary + getSalary() + getSalary() Association - Association Class Design Decisions

  45. prerequisites 0..* Course Association - Recursive association

  46. 0..1 0..1 has School Department 1 1 1..n 1..n 1..n 1..n 1..n 1..n assignedTo member -chairperson 1..n n n 1..n 0..1 attends teaches Student Course Instructor n n 1..n 1..n n n Association - Example

  47. Relationships: Dependency • A relationship between two model elements where a change in one may cause a change in the other • Non-structural, “using” relationship Client Supplier Component Class Supplier Client Package Dependency relationship ClientPackage SupplierPackage Dependency relationship

  48. Course Professor Dependency – Example class Professor { public void teach(Course c) { ……..} …………….. } class Professor { public void teach() { Course c = new Course(); ……..} …………….. }

  49. HelloWorld paint() Example: HelloWorld.java importjava.applet.Applet; importjava.awt.Graphics; publicclassHelloWorldextendsApplet { public void paint(Graphics g) { g.drawString("Hello World!", 50, 25); } } Applet Dependency relationship Graphics

  50. Employee Engineer Manager Relationships: Generalization • A relationship among classes where one class shares the structure and/or behavior of one or more classes • Defines a hierarchy of abstractions in which a subclass inherits from one or more superclasses • Single inheritance • Multiple inheritance • an “is-a-kind of” relationship Generalization relationship

More Related