1 / 48

UML

UML. Unified Modeling Language. Model. The heart of object-oriented problem solving is the construction of a model. Several modeling tools are wrapped under the heading of the UML ™. The UML is applicable to object-oriented problem solving.

aysel
Télécharger la présentation

UML

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. UML Unified Modeling Language

  2. Model • The heart of object-oriented problem solving is the construction of a model. • Several modeling tools are wrapped under the heading of the UML™.

  3. The UML is applicable to object-oriented problem solving • A model is an abstraction of the underlying problem. • The domain is the actual world from which the problem comes. • Models consist of objects that interact by sending each other messages. • The values of an object's attributes determine its state. • Classes are the "blueprints" for objects. A class wraps attributes (data) and behaviors (methods or functions) into a single distinct entity. • Objects are instances of classes.

  4. Unified Modeling Language • UMLprovides structure for problem solving. • A method for modelingObject Oriented Programs. • A means for visualizing, constructing and documenting software projects. • Promotes component reusability. • You will not understand what your algorithm does two weeks after you wrote it. But if you have the model, you will catch up fast and easily. • Teamwork for parallel development of large systems. • UMLincludes 13 diagrams.

  5. UML Modeling Steps

  6. Use case diagrams • describe what a system does from the standpoint of an external observer. (rather than how) • It is a scenario of what happens when someone interacts with the system. • A use case is a summary of scenarios for a single task or goal. • An actor is who or what initiates the events involved in that task. • The connection between actor and use case is a communication association .

  7. Example • "A patient calls the clinic to make an appointment for a yearly checkup. The receptionist finds the nearest empty time slot in the appointment book and schedules the appointment for that time slot. "

  8. Multiple actors multiple cases

  9. Candy Machine Case Study Requirements Textual Analysis UML Modeling Java Implementation

  10. Candy Machine Requirements A place to buy candy is from a candy machine. The candy machine has four dispensers to hold and release items sold by the candy machine as well as a cash register. The machine sells four products— candies, chips, gum, and cookies— each stored in a separate dispenser. The program should do the following: • Showthe customer the different productssold by the candy machine • Let the customermakethe selection • Showthe customerthe cost of the item selected • Acceptmoney from the customer • Return change • Release the item; that is, makethe sale

  11. Textual Analysis for First UML Use Cases Diagram +Use Cases Description Step 1: Identify Actors A place to buy candy is from a candy machine. The candy machine has four dispensers to hold and release items sold by the candy machine as well as a cash register. The machine sells four products— candies, chips, gum, and cookies— each stored in a separate dispenser. The program should do the following: • Showthe Customer the different productssold by the candy machine • Let the Customermakethe selection • Showthe Customerthe cost of the item selected • Acceptmoney from the Customer • Return change • Release the item; that is, makethe sale

  12. Textual Analysis for First UML Use Cases Diagram +Use Cases Description UC Step 2: Identify Use Cases A place to buy candy is from a candy machine. The candy machine has four dispensers to hold and release items sold by the candy machine as well as a cash register. The machine sells four products—candies, chips, gum, and cookies— each stored in a separate dispenser. UC2: Sell Product The program should do the following: • Showthe Customer the different productssold by the candy machine • Let the Customermakethe selection • Showthe Customerthe cost of the item selected • Acceptmoney from the Customer • Return change • Release the item; that is, makethe sale UC1: Show Selection UC3: Make Selection UC4: Get Product Cost UC5: Accept Money UC6: Return Change UC7: Make Sale

  13. First UML MODEL:UML Use Cases Diagram + Use Cases Description Step 3: Draw UML Use Cases Diagram Candy Machine UC1: Show Selection UC2: Sell Products UC3: Make Selection UC4: Get Product Cost UC5: Accept Money UC6: Return Change UC7: Make Sale

  14. First UML MODEL:UML Use Cases Diagram + Use Cases Description Step 4: UML Use Cases Description Description UC1:Show Selection Menu with Welcome to Shelly’s Candy Shop To select an item, enter: 1. for Candy 2. for Chips 3. for Gum 4. for Cookies 9. to exit Same for the other 6 Use Cases

  15. UML Modeling Steps

  16. Class diagrams • A Class diagram gives an overview of a system by showing its classes and the relationships among them.

  17. kinds of relationships • association -- a relationship between instances of the two classes. There is an association between two classes if an instance of one class must know about the other in order to perform its work. In a diagram, an association is a link connecting two classes. • aggregation -- an association in which one class belongs to a collection. An aggregation has a diamond end pointing to the part containing the whole. In our diagram, Order has a collection of OrderDetails. • generalization -- an inheritance link indicating one class is a superclass of the other. A generalization has a triangle pointing to the superclass. Payment is a superclass of Cash, Check, and Credit.

  18. Textual Analysis for Second UML MODEL:UML Classes Diagram + Methods Pseudocode Step 1: Identify Classes CandyMachine A place to buy candy is from a Candy Machine. The candy machine has four dispensers to hold and release items sold by the candy machine as well as a cash register. The machine sells four products— candies, chips, gum, and cookies— each stored in a separate dispenser. Dispenser The program should do the following: • Showthe Customer the different productssold by the candy machine • Let the Customermakethe selection • Showthe Customerthe cost of the item selected • Acceptmoney from the Customer • Return change • Release the item; that is, makethe sale CashRegister

  19. Textual Analysis for Second UML MODEL:UML Classes Diagram + Methods Pseudocode Step 1: Identify Classes Place, candy, candy machine, cafeteria, dispenser, items, cash register, chips, gum, cookies, customer, products, cost ( of the item), money, and change. In this description of the problem, products stand for items such as candy, chips, gum, and cookies. In fact, the actual product in the machine is not that important. What is important is to note that there are four dispensers, each capable of dispensing one product. Further, there is one cash register. Thus, the candy machine consists of four dispensers and one cash register.

  20. Textual Analysis for Second UML MODEL:UML Classes Diagram + Methods Pseudocode Step 2: Identify Attributes A place to buy candy is from a Candy Machine. The candy machine has four dispensers to hold and release items sold by the candy machine as well as a cash register. The machine sells four products— candies, chips, gum, and cookies— each stored in a separate dispenser – need numberOfItems and cost. numberOfItems cost Dispenser The program should do the following: • Showthe Customer the different productssold by the candy machine • Let the Customermakethe selection • Showthe Customerthe cost of the item selected • Acceptmoney from the Customer • Return change – need cashOnHand • Release the item; that is, makethe sale CashRegister cashOnHand

  21. Textual Analysis for Second UML MODEL:UML Classes Diagram + Methods Pseudocode Step 3: Identify verbsMethods The relevant verbs are show ( selection), make ( selection), show ( cost), accept ( money), return ( change), and make ( sale). The verbs show ( selection) and make ( selection) relate to the Candy Machine. The verbs show ( cost) and make ( sale) relate to the Dispenser. Similarly, the verbs accept ( money) and return ( change) relate to the Cash Register.

  22. Second UML MODEL:UML Classes Diagram + Methods Pseudocode Step 4: Draw OOA UML Classes Diagram A place to buy candy is from a Candy Machine. The candy machine has four dispensers to hold and release items sold by the candy machine as well as a cash register. The machine sells four products— candies, chips, gum, and cookies— each stored in a separate dispenser – need numberOfItems and cost. numberOfItems cost Dispenser The program should do the following: • Showthe Customer the different productssold by the candy machine • Let the Customermakethe selection • Showthe Customerthe cost of the item selected • Acceptmoney from the Customer • Return change – need cashOnHand • Release the item; that is, makethe sale CashRegister cashOnHand

  23. Textual Analysis for Second UML MODEL:UML Classes Diagram + Methods Pseudocode Step 5: Identify Objects You can see that the program you are about to write is supposed to deal with dispensers and cash registers. That is, the main objects are four dispensers and a cash register. Because all the dispensers are of the same type, you need to create a class, say, Dispenser, to create the dispensers. Similarly, you need to create a class, say, CashRegister, to create a cash register. We will create the classCandyMachine containing the four dispensers, a cash register, and the application program.

  24. Dispenser To make the sale, at least one item must be in the dispenser and the customer must know the cost of the product. Therefore, the data members of a dispenser are:  Product cost  Number of items in the dispenser Cash Register The cash register accepts money and returns change. Therefore, the cash register has only one data member, which we call  cashOnHand Candy Machine The classCandyMachine has four dispensers and a cash register. You can name the four dispensers by the items they store. Therefore, the candy machine has five data members— four dispensers and a cash register.

  25. UMLDispenser Class DiagramAttributes – instance variables Dispenser To make the sale, at least one item must be in the Dispenser and the Customer must know the cost of the product. Therefore, the instance variable of a Dispenser are:  Product cost  Number Of Items in the Dispenser

  26. UMLCash Register Class DiagramAttributes – instance variables Cash Register The cash register accepts money and returns change. Therefore, the cash register has only one instance variable, which we call:  cashOnHand

  27. UMLCandy Machine Class DiagramAttributes – instance variables Candy Machine The classCandyMachine has four dispensers and a cash register. You can name the four dispensers by the items they store. Therefore, the candy machine has five instance variables—  four dispensers  candy,  chips,  gum,  cookies  and a  cash Register.

  28. UMLClass DiagramVerbs - Methods The relevant verbs are show ( selection), make ( selection), show ( cost), accept ( money), return ( change), and make ( sale). The verbs show ( selection) and make ( selection) relate to the Candy Machine. The verbs show ( cost) and make ( sale) relate to the Dispenser. Similarly, the verbs accept ( money) and return ( change) relate to the Cash Register.

  29. UMLCandy Machine Class DiagramVerbs - Methods The verbs show ( selection) and make ( selection) relate to the Candy Machine. Thus, the two possible operations are:  showSelection: Show the number of products sold by the Candy Machine.  makeSelection: Allow the customer to select the product.

  30. UMLDispenser Class DiagramVerbs - Methods The verbs show ( cost) and make ( sale) relate to the Dispenser. The verb show ( cost) applies to either printing or retrieving the value of the data member cost. The verb make ( sale) applies to reducing the number of items in the dispenser by 1. Of course, the Dispenser has to be nonempty. You must also provide an operation to set the cost and the number of items in the dispenser. Thus, the operations for a Dispenser object are:  getCount: Retrieve the number of items in the Dispenser.  getProductCost: Retrieve the cost of the item.  makeSale: Reduce the number of items in the Dispenser by 1.  setProductCost: Set the cost of the product.  setNumberOfItems: Set the number of items in the Dispenser

  31. UMLCash Register Class DiagramVerbs - Methods Similarly, the verbs accept (money) and return (change) relate to the Cash Register. The verb accept ( money) applies to updating the money in the cash register by adding the money deposited by the customer. Similarly, the verb return ( change) applies to reducing the money in the cash register by returning the overpaid amount ( by the customer) to the customer. You also need to ( initially) set the money in the cash register and retrieve the money from the cash register. Thus, the possible operations on a cash register are:  acceptAmount: Update the amount in the cash register.  returnChange: Return the change.  getCashOnHand: Retrieve the amount in the cash register.  setCashOnHand: Set the amount in the cash register.

  32. Second UML MODEL: UML Classes Diagram + Methods Pseudocode Step 5: Draw OOD UML Classes Diagram

  33. Second UML MODEL:UML Classes Diagram + MethodsPseudocode Step 6: Detailed Design Pseudocode for showSelection method • Show the selection to the Customer • Get selection • If selection is valid and the Dispenser corresponding to the selection is not empty, sell the product showSelection: Show the number of products sold by the Candy Machine.

  34. Second UML MODEL:UML Classes Diagram + MethodsPseudocode Step 6: Detailed Design Pseudocode for makeSale method • If the Dispenser is nonempty: • Prompt customer to enter the item cost • Get the amount entered by the customer • If the amount entered by the customer is less than the cost of the product • Prompt customer to enter additional amount • Calculate total amount entered by the customer • If amount entered by the customer is at least the cost of the product • Update the amount in the cash register • Sell the product; that is, decrement the number of items in the Dispenser by 1 • Display an appropriate message • If amount entered is less than cost of item • Return the amount • If the Dispenser is empty • Tell the customer that this product is sold out

  35. Second UML MODEL:UML Classes Diagram + MethodsPseudocode Step 6: Detailed Design Pseudocode for main method • Declare a variable of type cashRegister • Declare and initialize four objects dispenserType • For example: • The statement dispenserType chips(100, 65); creates a Dispenser object, chips, to hold chips; the number of items in the Dispenser is 100 and the cost of an item is 65 cents

  36. Second UML MODEL:UML Classes Diagram + MethodsPseudocode Step 6: Detailed Design Pseudocode for main method • Declare additional variables as necessary • Show menu • Get the selection • While not done (9 exits) • Sell product (makeSale) • Show selection (showSelection) • Get selection

  37. a role name is to clarify the nature of the association. For example, an OrderDetail is a line item of each Order. • A navigability arrow on an association shows which direction the association can be traversed or queried. An OrderDetail can be queried about its Item, but not the other way around. The arrow also lets you know who "owns" the association's implementation; in this case, OrderDetail has an Item. Associations with no navigability arrows are bi-directional. • The multiplicity of an association end is the number of possible instances of the class associated with a single instance of the other end. Multiplicities are single numbers or ranges of numbers. In our example, there can be only one Customer for each Order, but a Customer can have any number of Orders.

  38. most common multiplicities

  39. composition • Composition relationships are a strong form of containment or aggregation. Aggregation is a whole/part relationship. • In this case, Circle is the whole, and Point is part of Circle. • Composition also indicates that the lifetime of Point is dependent upon Circle. This means that if Circle is destroyed, Point will be destroyed with it

  40. composition

  41. Aggregation / Association the Window class contains many Shape instances. In UML the ends of a relationship are referred to as its “roles”. Notice that the role at the Shape end of the aggregation is marked with a “*”. This indicates that the Window contains many Shape instances ( in association the state of an object depends on another object). Notice also that the role has been named (itsShapes).

  42. Association Aggregation denotes whole/part relationships whereas associations do not (no relation)

  43. Packages are group of classes The dotted arrows are dependencies

  44. Dependency a dashed arrow between the Shape class and the DrawingContext class. This is the dependency relationship. This relationship simply means that Shape somehow depends upon DrawingContext. Shape depends on drawing context. In C++ this almost always results in a #include.

  45. Object diagrams show instances instead of classes a university Department can contain lots of other Departments

  46. A concrete example Instance names are underlined in UML diagrams

  47. Multiplicity =allowable nb of instance • C++ Declaration UML Multiplicity Range • Foo 1..1 • Foo * 0..* • Foo [] 0..* • Foo *[] 0..* • Foo [n] n..n • Foo *[n] 0..n • Foo ** 0..* • Foo & 1..1 • list<Foo> 0..* • auto_ptr<Foo *> 0..1

  48. Interfaces There are classes that have nothing but pure virtual functions. In Java such entities are not classes at all; they are a special language element called an interface.

More Related