Object Oriented Analysis and Design Use Case Realization

Matthew Dailey
Computer Science and Information Management Asian Institute of Technology

Matthew Dailey (CSIM-AIT)

Use Case Realization

1 / 34

Readings

Readings for these lecture notes: - Larman (2005), Applying UML and Patterns: An Introduction to Object-Oriented Analysis and Design and Iterative Development, 3rd edition, Chapters 18–21. Some material c Larman (2005).

Matthew Dailey (CSIM-AIT)

Use Case Realization

2 / 34

Outline

1

Introduction

2

Use case realization

3

Implementation considerations

4

Wrap-Up

Matthew Dailey (CSIM-AIT)

Use Case Realization

3 / 34

The resulting detailed designs are called use case realizations. Using the principles of responsibility assignment.Introduction Introduction We now turn to use case realization and implementation as it typically occurs during Elaboration. that design modeling. Remember once again. we will design the collaborations needed to implement the system operations discovered during SSD analysis. Matthew Dailey (CSIM-AIT) Use Case Realization 4 / 34 . should be brief and should focus on the interesting parts of the design. Once we have detailed designs for the interesting parts of the use case scenario we’ve chosen to implement. like analysis modeling. we can proceed to implementation.

Outline 1 Introduction 2 Use case realization 3 Implementation considerations 4 Wrap-Up Matthew Dailey (CSIM-AIT) Use Case Realization 5 / 34 .

a use case realization shows how a use case is realized in the design model. They generally only describe one scenario. so might be better termed scenario realizations.Use case realization Introduction In the UP. Matthew Dailey (CSIM-AIT) Use Case Realization 6 / 34 .

. quantity ) Register . and detailed postcondition to satisfy System Sequence Diagrams : Register enterItem (itemID..... validation starting events to design for. Use Case Text system events : System Supplementary Specification Requirements Use Case Diagram ideas for the postconditions functional requirements that must be realized by the objects Glossary non-functional requirements domain rules inspiration for names of some software domain objects Operation: enterItem(…) Post-conditions: -... Now we begin with the domain/application layer controllers we’ve assigned the relevant system operation to. ..... 3. .. quantity) item details.. 18.... Customer arrives .) ..Use case realization Introduction Sample UP Artifact Relationships Domain Model Business Modeling Sale date . formats... Fig. Larman (2005). Cashier enters item identifier.* Sales LineItem quantity . and design their collaborations with domain objects. quantity) Design Model : ProductCatalog : Sale Design d = getProductDescription(itemID) addLineItem( d.) . makeNewSale() enterItem(. we can begin to design our use case realizations. 2....1 Matthew Dailey (CSIM-AIT) Use Case Realization 7 / 34 . Use-Case Model Process Sale Process Sale Cashier use case names 1.... Operation Contracts : Cashier system operations make NewSale() enterItem (id. . Now that we have some idea of how to assign responsibilities to objects. ProductCatalog * 1 getProductDescription(. 1 1.

enterItem :Register 1: ??? endSale :Register 1: ??? makePayment :Register 1: ??? UI LAYER DOMAIN LAYER Larman (2005). 18. makeNewSale. etc.2 Matthew Dailey (CSIM-AIT) Use Case Realization 8 / 34 . are the system operations from the SSD each major interaction diagram starts with a system operation going into a domain layer controller object..Use case realization System operations and use case realizations Key point: the system operations in the SSDs become the starting messages entering the domain layer controllers. such as Register makeNewSale Window objects or GUI widget objects or Web control objects :Register 1: ??? ... Fig.

..Use case realization System operations and use case realizations Once the controller for system-level messages in a use case is identified. we will refine the design.) desc = getProductDesc( itemID ) .. : Register makeNewSale create : Sale Window objects or GUI widget objects or Web control objects ..3 Matthew Dailey (CSIM-AIT) Use Case Realization 9 / 34 .. : ProductCatalog UI LAYER DOMAIN LAYER Larman (2005). : Register enterItem(.. Fig. 18.

Matthew Dailey (CSIM-AIT) Use Case Realization 10 / 34 . Introduce new software classes unrelated to the domain model as necessary. operation contract.Use case realization Getting started Some simple tips for getting started: Start with the detailed use case description. Discuss with the customer if necessary. using the objects in the domain model. Start designing. Ignore the domain model when it’s not useful. Create new/missing conceptual classes as needed. and so on.

Although Startup is logically first.Use case realization System startup use case Almost every system has a Startup use case. Matthew Dailey (CSIM-AIT) Use Case Realization 11 / 34 . you should design it last! Why? We don’t know what we need to initialize until we design the rest of the use case realizations. Clearly code for the Startup use case is needed in the very first iteration.

Use case realization Choosing the controller class First step: choose the controller class. Matthew Dailey (CSIM-AIT) Use Case Realization 12 / 34 . Apply the principles of the GRASP Controller pattern to assign responsibility to an appropriate controller for each system-level operation.

Use case realization Example: makeNewSale Example: system operation makeNewSale Operation: makeNewSale() Cross References: Use Cases: Process Sale Preconditions: none Postconditions: A Sale instance s was created. s was associated with the Register. What class should we use for the controller object that receives the makeNewSale() message? Matthew Dailey (CSIM-AIT) Use Case Realization 13 / 34 . Attributes of s were initialized.

Matthew Dailey (CSIM-AIT) Use Case Realization 14 / 34 . Register. the controller could represent the system. a root object. This suggests Store. or POSSystem. or a subsystem. a specialized device.Use case realization Example: makeNewSale On the one hand. Here Register seems most suitable because it represents the device the cashier is interacting with and will not have too many other responsibilities. Or we could use a use case controller. This suggests ProcessSaleHandler or ProcessSaleSession.

18.Use case realization Example: makeNewSale Since we chose Register as the controller. :Register makeNewSale create :Sale Larman (2005).5   Matthew Dailey (CSIM-AIT) Use Case Realization 15 / 34 . mainly creating a new Sale object. it becomes responsible for processing the makeNewSale system event. Fig.

18. Fig. Since Sale contains and maintains a list of SalesLineItem instances. by the Creator pattern it is a good candidate to create the list: by Creator and Controller :Register Register creates a Sale by Creator makeNewSale create :Sale create by Creator. when a Sale is created.Use case realization Example: makeNewSale Next. we should initialize the SalesLineItem list for that Sale. Sale creates an empty collection (such as a List) which will eventually hold SalesLineItem instances lineItems : List<SalesLineItem> this execution specification is implied to be within the constructor of the Sale instance Larman (2005).6 Matthew Dailey (CSIM-AIT) Use Case Realization 16 / 34 .

Use case realization Example: enterItem Using the same principles plus the Expert pattern to find the relevant product description. we can design the enterItem collaboration: by Controller by Creator enterItem(id.1: desc = get(id) 2. Fig.7   Matthew Dailey (CSIM-AIT) Use Case Realization 17 / 34 . qty) :Sale 1: desc = getProductDesc(id) :Product Catalog 2. qty) :Register 2: makeLineItem(desc. qty) by Expert sl: SalesLineItem 1. 18.1: create(desc.2: add(sl) lineItems : List<SalesLineItem> add the newly created SalesLineItem instance to the List : Map<ProductDescription> Larman (2005).

Fig. 18.Use case realization Example: endSale Suppose the endSale operation contract simply specifies that Sale.9 Matthew Dailey (CSIM-AIT)  Use Case Realization  18 / 34 .isComplete becomes true. This is simple to design since Sale is the Expert for its own attributes: endSale( :Register 1: becomeComplete s :Sale by Controller by Expert Larman (2005).

we note hat the system needs to present the customer with the total price..10 Matthew Dailey (CSIM-AIT) Use Case Realization 19 / 34 .n]: st = getSubtotal lineItems[ i ]: SalesLineItem 1. We don’t worry about the UI at this point but we should make sure that the total can be calculated: by Expert by Expert UML: note the selector notation to select elements from the lineItems collection tot = getTotal :Sale 1 * [i = 1.1: pr = getPrice :ProductDescription Larman (2005).Use case realization Example: getTotal In the use case specification. 18. with taxes calculated. Fig.

Use case realization More examples See Larman Chapter 18 for many more examples. Matthew Dailey (CSIM-AIT) Use Case Realization 20 / 34 .

The initial domain object is normally responsible for creating all contained objects. The initial domain object should be at or near the “root” of the containment or aggregation hierarchy.Use case realization Startup Once you have designs for the scenarios you will implement. but the basic idea is to create an initial domain object or set of objects. The specifics depend on the platform. Matthew Dailey (CSIM-AIT) Use Case Realization 21 / 34 . you know what needs to be initialized.

.Use case realization Startup For example. Matthew Dailey (CSIM-AIT) Use Case Realization 22 / 34 . ProcessSaleJFrame frame = new ProcessSaleJFrame( register ). Store store = new Store(). // The Store creates some other domain objects.. a ProductCatalog. } } Based on the other system operation designs. we know the Store needs a Register. . suppose we choose Store as the initial domain object: public class Main { public static void main( String[] args ) { // Store is the initial domain object.getRegister(). and ProductDescriptions. Register register = store.

2.Use case realization Startup Possible design for Store’s constructor: pass a reference to the ProductCatalog to the Register. 18. Fig.1*: create(id.1: create pc: ProductCatalog 1.20 Matthew Dailey (CSIM-AIT) Use Case Realization 23 / 34 . price. pd) create an empty collection object descriptions: Map<ProductDescription> 1. so that it has permanent visibility to it create :Store 2: create(pc) :Register by Creator 1: create 1. description) pd: ProductDescription the * in sequence number indicates the message occurs in a repeating section Larman (2005).2*: put(id.2: loadProdSpecs() 1.2.

Use case realization Domain layer-UI layer connection at startup There are two major approaches to connecting the UI with the domain layer: An initialization method creates a UI and a domain object. Matthew Dailey (CSIM-AIT) Use Case Realization 24 / 34 . and passes the domain object to the UI object. The UI calls a factory object to obtain a domain object.

Outline 1 Introduction 2 Use case realization 3 Implementation considerations 4 Wrap-Up Matthew Dailey (CSIM-AIT) Use Case Realization 25 / 34 .

we need to start implementing. Here we mention a few important considerations as we map our designs to code: Visibility of objects to each other Database mapping Mapping DCD classes to implementation classes Test-driven development Refactoring Matthew Dailey (CSIM-AIT) Use Case Realization 26 / 34 .Implementation considerations Introduction Now that we know the basics of object design and responsibility assignment.

B needs to be visible to A. Matthew Dailey (CSIM-AIT) Use Case Realization 27 / 34 . It may be a global variable in some languages like C++ (not recommended) or a Singleton (GoF. preferred). It may be created within A’s method or be the returned from a method invocation.Implementation considerations Visibility For object A to pass a message to object B. There are 4 main ways for A to “see” B: Attribute visibility: B is an attribute of A Parameter visibility: B is a parameter to a method of A Local visibility: B is a local variable in one of A’s methods. Global visibility: B is globally accessible.

every project would implement its own ORM. Hibernate and the Glassfish Java Persistence module (Toplink) can run standalone or in a standard Web container such as Tomcat. ORMs are built in to the major platforms.Use case realization Database retrieval The approach to persistence depends on the implementation platform. Not so long ago. JPA is standard in all EJB 3. Typically.0 containers. Nowadays. Matthew Dailey (CSIM-AIT) Use Case Realization 28 / 34 . we use an object-relational mapper (ORM) or a native object-oriented database. The persistence solution has architectural consequences so should be deployed in the first iteration.

map the DCD classes to software classes. by hand or using the UML tool. Put the persistence solution in place as soon as possible.Implementation considerations Mapping to code As the design progresses. For Java: ArrayList: for growing. ordered lists HashMap: for key-based lookup An exception handling strategy will be needed early on. 1-to-many relationships need to be implemented with collections. Matthew Dailey (CSIM-AIT) Use Case Realization 29 / 34 .

Programmers become satisfied with the challenge of writing quality code to pass a test. particularly unit tests. Benefits: Thorough unit tests get written. Use JUnit for Java (built into Eclipse). It’s easy to verify that code changes preserve functionality. Matthew Dailey (CSIM-AIT) Use Case Realization 30 / 34 .Implementation considerations Test-driven development Developers should write the test cases. before writing code. The test suite can be automated with tools such as CruiseControl. Interfaces are carefully considered before coding begins.

Study them. and use the IDE’s refactoring support (e. “Extract Method” in Eclipse). one at a time. Find classes with too much code and break them up.g.Implementation considerations Refactoring Apply small behavior-preserving transformations. Common refactorings: Find duplicated code and factor it out. Factor private helper methods out of big methods. Find classes with too many instance variables and break them up. Matthew Dailey (CSIM-AIT) Use Case Realization 31 / 34 . and re-run the test cases to verify them. There are about 100 well-known named refactorings.

Outline 1 Introduction 2 Use case realization 3 Implementation considerations 4 Wrap-Up Matthew Dailey (CSIM-AIT) Use Case Realization 32 / 34 .

the main tasks are to get more experience with architectures and learn more design patterns. Matthew Dailey (CSIM-AIT) Use Case Realization 33 / 34 .Wrap-Up What else? Beyond the basics we’ve explored so far.

Wrap-Up Exercises Some exercises to practice these principles: Do use case realizations for the case study project Iteration 1 Document the designs on the project wiki Prepare your implementation platform: We’ll need Eclipse with the Java EE tools. and the Hibernate ORM. the Tomcat application server. Matthew Dailey (CSIM-AIT) Use Case Realization 34 / 34 .

Sign up to vote on this title
UsefulNot useful