Presentation is loading. Please wait.

Presentation is loading. Please wait.

Feb 200592.3913 Ron McFadyen1 Use Case Realizations with GRASP Patterns “The assignment of responsibilities and design of collaborations are very important.

Similar presentations


Presentation on theme: "Feb 200592.3913 Ron McFadyen1 Use Case Realizations with GRASP Patterns “The assignment of responsibilities and design of collaborations are very important."— Presentation transcript:

1 Feb 200592.3913 Ron McFadyen1 Use Case Realizations with GRASP Patterns “The assignment of responsibilities and design of collaborations are very important and creative steps during design” “there is no ‘magic’ or unjustifiable decisions in object design” “A use-case realization describes how a particular use case is realized within the design model, in terms of collaborating objects” makeNewSale enterItem endSale makePayment startUp You should review these sections

2 Feb 200592.3913 Ron McFadyen2 Ch 17: Use Case Realizations with GRASP Patterns makeNewSale 1 st concern: who/what is going to be responsible for handling the system operation makeNewSale? Decision: Using the Controller Pattern … since there aren’t very many system operations and since Register (in our domain) represents the overall system, we choose Register as a “façade” controller.

3 Feb 200592.3913 Ron McFadyen3 Use Case Realizations with GRASP Patterns By “Controller”, Register is our “façade” controller. makeNewSale() :Register

4 Feb 200592.3913 Ron McFadyen4 Use Case Realizations with GRASP Patterns public class Register {… public makeNewSale() { … } We have just decided that Register must have a method makeNewSale Here, we are looking ahead to some code written to support the design Register makeNewSale …

5 Feb 200592.3913 Ron McFadyen5 Use Case Realizations with GRASP Patterns 2 nd concern: who/what is going to be responsible for creating a Sale? Should Register delegate the responsibility or …? Since Register (in the domain) actually records a Sale then, by “Creator”, we decide that Register will do this. Register has the data and it needs to keep track of a Sale, so …

6 Feb 200592.3913 Ron McFadyen6 Use Case Realizations with GRASP Patterns By “Creator”, Register creates a Sale. makeNewSale() :Register create() :Sale

7 Feb 200592.3913 Ron McFadyen7 Use Case Realizations with GRASP Patterns public class Register {… Private Sale sale; … public makeNewSale() { sale = new Sale(); } The method makeNewSale creates the sale object Here, we are looking ahead to some code written to support the design

8 Feb 200592.3913 Ron McFadyen8 Use Case Realizations with GRASP Patterns 3 rd concern: Sale needs to know of its SalesLineItems. A container for these is required. Who/What should create this? Since Sale will contain the lines, by “Creator”, we decide that Sale will do this…

9 Feb 200592.3913 Ron McFadyen9 Use Case Realizations with GRASP Patterns By “Creator”, Register creates a Sale. makeNewSale() :Register create() :Sale create() : :SalesLineItem

10 Feb 200592.3913 Ron McFadyen10 Use Case Realizations with GRASP Patterns By “Creator”, Register creates a Sale. makeNewSale() :Register create() :Sale create() lineItems: List 3 rd edition

11 Feb 200592.3913 Ron McFadyen11 Use Case Realizations with GRASP Patterns public class Sale {private List lineItems = new ArrayList(); private Date date = new Date(); private boolean isComplete = false; private Payment payment; … The constructor for Sale creates the container for the line items. Sale contains a list of line items

12 Feb 200592.3913 Ron McFadyen12 Use Case Realizations with GRASP Patterns enterItem 1 st concern: who/what is going to be responsible for handling the system operation enterItem? We continue using the Controller Pattern … Register is responsible for handling enterItem.

13 Feb 200592.3913 Ron McFadyen13 Use Case Realizations with GRASP Patterns Contract for enteritem specifies Preconditions: A Sale is underway Postconditions: salesLineItem is created It is associated with the current Sale Its quantity is set It is associated with a ProductSpecification By Creator, Sale can do this Sale stores the new sales line item in its collection The product specification will need to be found

14 Feb 200592.3913 Ron McFadyen14 Use Case Realizations with GRASP Patterns enterItem() :Register:Sale : :SalesLineItem 2:makeLineItem() 2.1:create() 2.2:add() Message 2 … see later slide

15 Feb 200592.3913 Ron McFadyen15 Use Case Realizations with GRASP Patterns enterItem() :Register:Sale : SalesLineItem 2:makeLineItem() 2.1:create() 2.2:add() Message 2 … see later slide lineItems: List 3 rd edition

16 Feb 200592.3913 Ron McFadyen16 Use Case Realizations with GRASP Patterns public class Sale {… public void makeLineItem (…, …) { lineItems.add ( new SalesLineItem (…, …) ) ; } The “add” message sent to the multiobject is handled within Sale. Sale has a list of line items The “create” message for a new sales line item

17 Feb 200592.3913 Ron McFadyen17 Use Case Realizations with GRASP Patterns public class SalesLineItem {private int quantity; private ProductSpecification productSpec; public void SalesLineItem (…spec, …quantity) { this.productSpec = spec ; this.quantity = quantity } The constructor for a sales line item arranges that the sales line item knows its product specification and its quantity

18 Feb 200592.3913 Ron McFadyen18 Use Case Realizations with GRASP Patterns enterItem 2 nd concern: who/what is going to be responsible for finding a match for a product specification? For doing a lookup? Who has knowledge of product specifications? Who is capable of doing a lookup? Expert suggests the product catalogue is the best candidate. The product catalogue contains the product specifications … the product catalogue has the information, it is the expert.

19 Feb 200592.3913 Ron McFadyen19 Use Case Realizations with GRASP Patterns enterItem() :Register : :ProductSpecification :ProductCatalog 1:getSpecification() 1.1:find()

20 Feb 200592.3913 Ron McFadyen20 Use Case Realizations with GRASP Patterns enterItem() :Register :ProductCatalog 1:getSpecification() 1.1:get() : Map 3 rd edition

21 Feb 200592.3913 Ron McFadyen21 Use Case Realizations with GRASP Patterns public class ProductCatalog { private Map productSpecifications = new HashMap(); … public ProductSpecification getSpecification (ItemID id) { Return( …. productSpecifications.get ( id ); } Collection of product specifications Method to find a specific item Handles the “find” message

22 Feb 200592.3913 Ron McFadyen22 Use Case Realizations with GRASP Patterns enterItem() :Register:Sale : :ProductSpecification :ProductCatalog : :SalesLineItem 1:getSpecification() 1.1:find() 2:makeLineItem() 2.1:create() 2.2:add()

23 Feb 200592.3913 Ron McFadyen23 Use Case Realizations with GRASP Patterns enterItem() :Register:Sale :ProductCatalog :SalesLineItem 1:getSpecification() 1.1get() 2:makeLineItem() 2.1:create() 2.2:add() : Map 3 rd edition lineItems: List

24 Feb 200592.3913 Ron McFadyen24 Use Case Realizations with GRASP Patterns Given the previous collaboration, what methods/responsibilities have been assigned to the various classes? RegisterSale ProductCatalog SalesLineItem


Download ppt "Feb 200592.3913 Ron McFadyen1 Use Case Realizations with GRASP Patterns “The assignment of responsibilities and design of collaborations are very important."

Similar presentations


Ads by Google