20101007 how smart use cases drive web development
DESCRIPTION
Use cases have been around for many years describing the requirements of software development projects. From a developer’s point of view, use cases are often seen as too abstract and too complex to develop code from. Until now, that is. During this interactive talk, presented by speaker Sander Hoogendoorn at Microsoft TechEd Europe 2010 in Berlin, will demonstrate how to model, generate and build smart use cases. This great technique allows you to model use cases at a much more pragmatic, low-granular level, enabling them to be implemented simply and directly into applications such as ASP.NET or Silverlight. Using many real-life code examples, the speaker will introduce both the positive impact that smart use cases have on your layered software architecture, as well as the design patterns required to implement them.TRANSCRIPT
Sander HoogendoornPrincipal Technology Officer
Capgemini
HOW SMART USE CASES DRIVE WEB DEVELOPMENT
2HOW SMART USE CASES DRIVE WEB DEVELOPMENT©2010 Capgemini. All Rights Reserved
Capgemini
� Principal technology officer
� Global agile thought leader
� Chief architect Accelerated Delivery Platform (ADP)
Other
� Author books and +200 articles in international magazines
� Appreciated speaker at +80 international conferences
� Microsoft Partner Advisory Council .NET
� Capping IT Off Blog
� Columns in Software Release Magazine, SDN Magazine
� Editorial boards Software Release Magazine, TiTM
� Advisory board @Portunity
Web
� www.sanderhoogendoorn.com
� www.smartusecase.com
� Twitter / LinkedIn : aahoogendoorn
SANDER HOOGENDOORN
3HOW SMART USE CASES DRIVE WEB DEVELOPMENT©2010 Capgemini. All Rights Reserved
AGENDA
Comparing requirements
techniques
Modeling
smart use cases
Smart use case driven
software architecture
Introducing
the task pattern
Generating code
from smart use cases
Unit testing
smart use cases
4HOW SMART USE CASES DRIVE WEB DEVELOPMENT©2010 Capgemini. All Rights Reserved
AGENDA
Comparing requirements
techniques
Modeling
smart use cases
Smart use case driven
software architecture
Introducing
the task pattern
Generating code
from smart use cases
Unit testing
smart use cases
User stories, huge cases and smart use cases
REQUIREMENT TECHNIQUES COMPARED
6HOW SMART USE CASES DRIVE WEB DEVELOPMENT©2010 Capgemini. All Rights Reserved
USER STORIES – APPLES AND PEARS
Often too unstructured
Unsuitable in complex
environments
7HOW SMART USE CASES DRIVE WEB DEVELOPMENT©2010 Capgemini. All Rights Reserved
COMPLEX IT LANDSCAPES
8HOW SMART USE CASES DRIVE WEB DEVELOPMENT©2010 Capgemini. All Rights Reserved
HUGE CASES Hard to build,
impossible to test
9HOW SMART USE CASES DRIVE WEB DEVELOPMENT©2010 Capgemini. All Rights Reserved
DIFFERENT LEVELS OF USE CASES
Cloud level
Kite level
Sea level
Fish level
Clam level
High summary
Summary
User goal
Sub-function
Too low
Products
Selling products
Search
book
Insert
orderline
Sell book
10HOW SMART USE CASES DRIVE WEB DEVELOPMENT©2010 Capgemini. All Rights Reserved
DIFFERENT LEVELS OF USE CASES
11HOW SMART USE CASES DRIVE WEB DEVELOPMENT©2010 Capgemini. All Rights Reserved
Traditional
use cases
Smart
use cases
Format Textual Visual
Granularity Different Unified
Estimate Hard Easy
Unit of work Lousy Good
Reuse Incidental Normal
Traceability Possible Normal
Testability Poor Good
Traditional use cases
� Only user goal level use cases
� Use cases ‘as they are intended’
� A single use case describesa single elementary business process
� Differ in granularity too much
� Law of Large Numbers does not apply
Smart use cases
� User goal and sub function level use cases
� Good unit of work and estimation
� A single elementary business process is modeledin a single use case diagram
� A single user goal level use case + auxiliary use cases at sub-function level
� Very similar granularity
DIFFERENT LEVELS OF USE CASES
12HOW SMART USE CASES DRIVE WEB DEVELOPMENT©2010 Capgemini. All Rights Reserved
AGENDA
Comparing requirements
techniques
Modeling
smart use cases
Smart use case driven
software architecture
Introducing
the task pattern
Generating code
from smart use cases
Unit testing
smart use cases
A YAGNI approach to requirements
SMART USE CASES
14HOW SMART USE CASES DRIVE WEB DEVELOPMENT©2010 Capgemini. All Rights Reserved
In traditional software development
� Analysis and design is done upfront
� Development only starts after all design is complete and perfect
Consequences
� No room for new or changing insights
� Possibly unnecessary work
Therefore
� Eliminate waste
� Maximize the amount of work not done
� Postpone work until you really need it
Benefits
� No unnecessary analysis and design work
� Allows for new and changing insights
� No handover, immediate feedback
YAGNI. YOU AIN’T GONNA NEED IT
15HOW SMART USE CASES DRIVE WEB DEVELOPMENT©2010 Capgemini. All Rights Reserved
AGILE REQUIREMENTS - APPROACH
D
E
F
SmartUse Cases
A
Project
Scope
D
Use Cases
A
B C
Hierarchical
Processes
B
D
D
Hierarchical
Processes
Chronological
Processes
Cloud Level Kite Level Sea Level Fish Level
C
16HOW SMART USE CASES DRIVE WEB DEVELOPMENT©2010 Capgemini. All Rights Reserved
CLOUD LEVEL
17HOW SMART USE CASES DRIVE WEB DEVELOPMENT©2010 Capgemini. All Rights Reserved
KITE LEVEL
18HOW SMART USE CASES DRIVE WEB DEVELOPMENT©2010 Capgemini. All Rights Reserved
Guidelines
� Identify re-use
� Model one form per use case
� Model one use case per web part
� Isolate unknown or complex functionality
� Model complex calculations
� Identify reports and analysis
� Isolate interaction with others
� Model services in service orientation
� Avoid low level interaction
(database, technical services)
IDENTIFYING SUB-FUNCTION LEVEL USE CASES
19HOW SMART USE CASES DRIVE WEB DEVELOPMENT©2010 Capgemini. All Rights Reserved
MODELING SMART USE CASES
20HOW SMART USE CASES DRIVE WEB DEVELOPMENT©2010 Capgemini. All Rights Reserved
MODELING SMART USE CASES – SEA AND FISH LEVEL
21HOW SMART USE CASES DRIVE WEB DEVELOPMENT©2010 Capgemini. All Rights Reserved
DESCRIBING USE CASES – SEA AND FISH LEVEL
Stereotypes
SMART USE CASES
23HOW SMART USE CASES DRIVE WEB DEVELOPMENT©2010 Capgemini. All Rights Reserved
Stereotypes in UML
� Marking model items gives explicit meaning to
the model
� Predefined stereotypes
� Custom definable stereotypes
Smart use case stereotypes
� Standardize analysis and design
� “This is a master-detail on product and order”
� “This service on customer is an aggregate”
� “We need a file import for handling the XMI”
� Facilitate easy estimation
� Commoditize realization of smart use case
� Facilitate easier (and automated) testing
SMART USE CASE STEREOTYPES
24HOW SMART USE CASES DRIVE WEB DEVELOPMENT©2010 Capgemini. All Rights Reserved
AGENDA
Comparing requirements
techniques
Modeling
smart use cases
Smart use case driven
software architecture
Introducing
the task pattern
Generating code
from smart use cases
Unit testing
smart use cases
An overview
SMART USE CASE DRIVEN ARCHITECTURE
26HOW SMART USE CASES DRIVE WEB DEVELOPMENT©2010 Capgemini. All Rights Reserved
Database consumer
� Domain oriented
� Data provided by database(s)
� But often database independent
Service consumer
� Domain oriented
� Data provided by service or middleware
� But protocol independent (SOAP or REST?)
Service provider
� Service oriented
� Data provided by contacts
� But domain oriented using data contracts
USING REFERENCE ARCHITECTURES
27HOW SMART USE CASES DRIVE WEB DEVELOPMENT©2010 Capgemini. All Rights Reserved
Presentation
Process
Domain
Data / Services
Outside world
Pages
UserControls
Panels
Use cases
Workflow
Domain objects / Entities
Factories / Repositories
Enums / Value objects / Smart references
[Mapping]
Table Gateways
Queries
[Mapping]
Database
28HOW SMART USE CASES DRIVE WEB DEVELOPMENT©2010 Capgemini. All Rights Reserved
Exact SAP BizTalk Java
Presentation
Process
Domain
Data / Services
Outside world
Pages
UserControls
Panels
Use cases
Workflow
Domain objects / Entities
Factories / Repositories
Enums / Value objects / Smart references
[Mapping]
Service gateways
Service locators
[Mapping]
Services / ESB
29HOW SMART USE CASES DRIVE WEB DEVELOPMENT©2010 Capgemini. All Rights Reserved
Presentation
Process
Domain
Data / Services
Outside world
Service contracts
Operation contracts
Data contracts
Use cases
Services
Domain objects / Entities
Factories / Repositories
Enums / Value objects / Smart references
[Mapping]
Table Gateways / Service Gateways
Queries / Service Locators
[Mapping]
Database
Services / ESB
Exact SAP BizTalk Java
30HOW SMART USE CASES DRIVE WEB DEVELOPMENT©2010 Capgemini. All Rights Reserved
ARCHITECTURE IN CODE
Web
� Pages, controls
Process
� Use cases / Tasks / Flow
Domain
� Factories / Repositories
� Domain Objects / Business rules
� Enums / Value Objects / References
� Search Objects
Data / Services
� Gateways
� Mappings / Describers
Database
31HOW SMART USE CASES DRIVE WEB DEVELOPMENT©2010 Capgemini. All Rights Reserved
AGENDA
Comparing requirements
techniques
Modeling
smart use cases
Smart use case driven
software architecture
Introducing
the task pattern
Generating code
from smart use cases
Unit testing
smart use cases
Introducing the Task Pattern
SMART USE CASE DRIVEN ARCHITECTURE
33HOW SMART USE CASES DRIVE WEB DEVELOPMENT©2010 Capgemini. All Rights Reserved
Presentation
Process
Domain
Data / Services
Outside world
Pages
UserControls
Panels
Use cases
Workflow
Domain objects / Entities
Factories / Repositories
Enums / Value objects / Smart references
[Mapping]
Table Gateways
Queries
[Mapping]
Database
34HOW SMART USE CASES DRIVE WEB DEVELOPMENT©2010 Capgemini. All Rights Reserved
Smart use cases
� Act as primary unit of work
� Model process and work flow
� Make traceable in code
� Interact with presentation and domain layers
� Create layer supertype (task)
� Create classes for individual smart use cases
Why?
� Create traceability
� Facilitate reuse
� Implement model view controller
� Facilitate easier functional testing
� Cheapen application maintenance
SMART USE CASES IN CODE
35HOW SMART USE CASES DRIVE WEB DEVELOPMENT©2010 Capgemini. All Rights Reserved
SMART USE CASES IN CODE
36HOW SMART USE CASES DRIVE WEB DEVELOPMENT©2010 Capgemini. All Rights Reserved
Command pattern – Definition
� Encapsulate a request as an object, thereby letting you parameterize clients with different requests, queue or log requests, and support undoable operations
Task pattern – Definition
� Encapsulate a smart use case as an object, thereby letting you parameterize it from different requests.
In practice
� Implement smart use cases independently
� Define a navigation mechanism
� Use smart use cases independently
� Allows for reuse of your smart use cases!
Useful when
� Always ☺
� Create a task manager!
TASK PATTERN
37HOW SMART USE CASES DRIVE WEB DEVELOPMENT©2010 Capgemini. All Rights Reserved
TASK PATTERN
38HOW SMART USE CASES DRIVE WEB DEVELOPMENT©2010 Capgemini. All Rights Reserved
TASK PATTERN IN PRACTICE
39HOW SMART USE CASES DRIVE WEB DEVELOPMENT©2010 Capgemini. All Rights Reserved
TASK PATTERN IN PRACTICE – RUNNING A USE CASE
40HOW SMART USE CASES DRIVE WEB DEVELOPMENT©2010 Capgemini. All Rights Reserved
TASK PATTERN
41HOW SMART USE CASES DRIVE WEB DEVELOPMENT©2010 Capgemini. All Rights Reserved
TASK PATTERN – START FIRST USE CASE
42HOW SMART USE CASES DRIVE WEB DEVELOPMENT©2010 Capgemini. All Rights Reserved
TASK PATTERN – START SECOND USE CASE
43HOW SMART USE CASES DRIVE WEB DEVELOPMENT©2010 Capgemini. All Rights Reserved
TASK PATTERN – WEB PAGE WITH SECOND USE CASE
44HOW SMART USE CASES DRIVE WEB DEVELOPMENT©2010 Capgemini. All Rights Reserved
TASK PATTERN – POST CONDITIONS SECOND USE CASE
45HOW SMART USE CASES DRIVE WEB DEVELOPMENT©2010 Capgemini. All Rights Reserved
TASK PATTERN – CONTINUE FIRST USE CASE
46HOW SMART USE CASES DRIVE WEB DEVELOPMENT©2010 Capgemini. All Rights Reserved
TASK PATTERN – WEB PAGE WITH FIRST USE CASE
47HOW SMART USE CASES DRIVE WEB DEVELOPMENT©2010 Capgemini. All Rights Reserved
TASK PATTERN – POST CONDITIONS FIRST USE CASE
Task management with the Manager-Provider Pattern
SMART USE CASE DRIVEN ARCHITECTURE
49HOW SMART USE CASES DRIVE WEB DEVELOPMENT©2010 Capgemini. All Rights Reserved
Definition
� Create a simple static facade (manager) for a
(set of) interfaced implementations (providers)
In practice
� Manager holds one or a collection of providers
� Provider implement a particular interface
� Manager has methods to call methods from
interface
� At run-time, using dependency injection, actual
providers are injected
MANAGER-PROVIDER PATTERN
50HOW SMART USE CASES DRIVE WEB DEVELOPMENT©2010 Capgemini. All Rights Reserved
MANAGER – VALIDATIONMANAGER
51HOW SMART USE CASES DRIVE WEB DEVELOPMENT©2010 Capgemini. All Rights Reserved
INTERFACE
52HOW SMART USE CASES DRIVE WEB DEVELOPMENT©2010 Capgemini. All Rights Reserved
MANAGER – INITIALIZATION (USING DEPENDENCY INJECTION)
53HOW SMART USE CASES DRIVE WEB DEVELOPMENT©2010 Capgemini. All Rights Reserved
CONFIGURATION OF IMPLEMENTATION
54HOW SMART USE CASES DRIVE WEB DEVELOPMENT©2010 Capgemini. All Rights Reserved
MANAGER - EXECUTING METHODS
55HOW SMART USE CASES DRIVE WEB DEVELOPMENT©2010 Capgemini. All Rights Reserved
CLIENT – CALLING METHODS
56HOW SMART USE CASES DRIVE WEB DEVELOPMENT©2010 Capgemini. All Rights Reserved
Useful when
� Generic services need to be called, which may have different implementations
� Manager prevents having to loop through each of a list of providers
� Flexibility to add or remove providers without changing application code
� Providers differ e.g. in development code, test code or deployed code
Use for
� Task Management
� View Management
� Binding and Persisting
� Resource Management
� State Management
� Logging
� Datasource interaction
� Testing!
MANAGER-PROVIDER PATTERN
57HOW SMART USE CASES DRIVE WEB DEVELOPMENT©2010 Capgemini. All Rights Reserved
AGENDA
Comparing requirements
techniques
Modeling
smart use cases
Smart use case driven
software architecture
Introducing
the task pattern
Generating code
from smart use cases
Unit testing
smart use cases
An introduction to pragmatic model driven development
GENERATING CODE FROM SMART USE CASES
59HOW SMART USE CASES DRIVE WEB DEVELOPMENT©2010 Capgemini. All Rights Reserved
Forms
Use cases
Domain
objects
Data / Serviceclasses
Databases
Software Architecture
TobagoMDA
Test
scenario’s
Frameworks
Specifications
Existing
Applications
Businessmodels
DomainModel
Smartuse cases
User interface
specification1. Map your
business processes
to smart use cases
1. Map your
business processes
to smart use cases
2. Set up your
domain model
2. Set up your
domain model3. Establish
your software
architecture(s)
3. Establish
your software
architecture(s)
4. Generate
your code using
a text template
engine
4. Generate
your code using
a text template
engine
5. Finalize your
application
5. Finalize your
application
60HOW SMART USE CASES DRIVE WEB DEVELOPMENT©2010 Capgemini. All Rights Reserved
Characteristics
� Load UML model (expressed in XMI)
� Load templates (from flat files)
� Combine elements from UML model with templates to generate deliverables
Templates
� Templates contains code that runs in template engine
� Templates might use a folder model
Generation process
� Ability to generate all or individual UML model elements
� Which UML model elements are supported?
� Generated deliverables can be code but also any other document type
MODEL DRIVEN DEVELOPMENT – TEMPLATE ENGINES
61HOW SMART USE CASES DRIVE WEB DEVELOPMENT©2010 Capgemini. All Rights Reserved
MODEL DRIVEN DEVELOPMENT - TEMPLATE ENGINES
Template engine knows (part of) the UML meta
model
Template engine knows (part of) the UML meta
model
Properties can be used in templates
Properties can be used in templates
62HOW SMART USE CASES DRIVE WEB DEVELOPMENT©2010 Capgemini. All Rights Reserved
MODEL DRIVEN DEVELOPMENT - TEMPLATES
63HOW SMART USE CASES DRIVE WEB DEVELOPMENT©2010 Capgemini. All Rights Reserved
GENERATE MANY THINGS E.G. TABLE CREATE SCRIPTS
A quick example
GENERATING CODE
65HOW SMART USE CASES DRIVE WEB DEVELOPMENT©2010 Capgemini. All Rights Reserved
A SIMPLE SMART USE CASE MODEL
uc Manage Customer
Site Administrator
(from A ctors)
«master detail»
Manage Customer
«search»
Select Customer
«define»
Define Contact
«extend»
«incl ude»
66HOW SMART USE CASES DRIVE WEB DEVELOPMENT©2010 Capgemini. All Rights Reserved
A SIMPLE DOMAIN MODEL
class Budapest.Business
«business class»
Cust omer
+ Name: string
+ Address: string
+ Postcode: Postcode
+ City: string
+ Country: SmartRef
+ Website: Url [0..1]
«business class»
Contact
+ Name: string
+ Email: Email [0..1]
+ Phone: PhoneNumber [0..1]
+ Department: Departments
«enumeration»
Depart ments
Sal es
Purchasing
Helpdesk
Management
*
67HOW SMART USE CASES DRIVE WEB DEVELOPMENT©2010 Capgemini. All Rights Reserved
USING TOBAGO MDA
68HOW SMART USE CASES DRIVE WEB DEVELOPMENT©2010 Capgemini. All Rights Reserved
GENERATED CODE IN ASP.NET
69HOW SMART USE CASES DRIVE WEB DEVELOPMENT©2010 Capgemini. All Rights Reserved
GENERATED CODE IN SILVERLIGHT
70HOW SMART USE CASES DRIVE WEB DEVELOPMENT©2010 Capgemini. All Rights Reserved
AGENDA
Comparing requirements
techniques
Modeling
smart use cases
Smart use case driven
software architecture
Introducing
the task pattern
Generating code
from smart use cases
Unit testing
smart use cases
Unit testing at the right level
UNIT TESTING SMART USE CASES
72HOW SMART USE CASES DRIVE WEB DEVELOPMENT©2010 Capgemini. All Rights Reserved
Presentation
Process
Domain
Data / Services
Outside world
Pages
UserControls
Panels
Use cases
Workflow
Domain objects / Entities
Factories / Repositories
Enums / Value objects / Smart references
[Mapping]
Table Gateways
Queries
[Mapping]
Database
73HOW SMART USE CASES DRIVE WEB DEVELOPMENT©2010 Capgemini. All Rights Reserved
UNIT TESTING SMART USE CASES
Unit test what?
� Methods from the task pattern
� Methods that are called from presentation
� Methods that collaborate with other use cases
� Methods that interact with domain
How?
� Create unit test for each smart use case
� Run methods from smart use case
� Validate outcome (using asserts)
Why?
� Great code coverage
� Regressions testing on smart use cases
� Code generation makes light work
74HOW SMART USE CASES DRIVE WEB DEVELOPMENT©2010 Capgemini. All Rights Reserved
UNIT TESTING SMART USE CASES
Test methods from Task Pattern
Run method
Validate outcome
75HOW SMART USE CASES DRIVE WEB DEVELOPMENT©2010 Capgemini. All Rights Reserved
UNIT TESTING SMART USE CASES
Test methods that interact with domain
Set up (in)valid domain object
Run method from use case
Validate outcome
Introducing a light weight smart use case unit testing framework
UNIT TESTING SMART USE CASES
77HOW SMART USE CASES DRIVE WEB DEVELOPMENT©2010 Capgemini. All Rights Reserved
Test environment
� Create test manager (using manager-provider)
� Mock actual use case environment
� Log events from environment to test manager
� Asserts by querying test manager
Task management
� (Possibly) avoid other task getting started
View management
� Don’t request actual web pages or forms
� Method calls from web pages are tested
Domain
� Handle actual validation, saves, removes
� Make sure business rules validate
Validation
� Validate, but handle by logging
A LIGHTWEIGHT SMART USE CASE UNIT TESTING FRAMEWORK
78HOW SMART USE CASES DRIVE WEB DEVELOPMENT©2010 Capgemini. All Rights Reserved
CONFIGURING TEST ENVIRONMENT
79HOW SMART USE CASES DRIVE WEB DEVELOPMENT©2010 Capgemini. All Rights Reserved
TEST MANAGER – LOGGING EVENTS
80HOW SMART USE CASES DRIVE WEB DEVELOPMENT©2010 Capgemini. All Rights Reserved
MOCKING ENVIRONMENT – LOGGING EVENTS
81HOW SMART USE CASES DRIVE WEB DEVELOPMENT©2010 Capgemini. All Rights Reserved
TEST MANAGER – QUERYING EVENTS
82HOW SMART USE CASES DRIVE WEB DEVELOPMENT©2010 Capgemini. All Rights Reserved
TEST MANAGER – RUNNING TESTS
Test methods that interact with domain
Set up (in)valid domain object
Run method from use case
Validate outcome
TAKEAWAYS
84HOW SMART USE CASES DRIVE WEB DEVELOPMENT©2010 Capgemini. All Rights Reserved
Smart use cases
� Solid unit of work in agile projects
� Easy estimation
� Identifying functional re-use early in projects
� Guarantee front-to-back traceability
� Great unit for (automated) testing
� Apply stereotypes for even more
standardization
� Use a REAL modeling tool
Software architecture
� Provide separate smart use cases layer
� Handles process, interaction and work flow
� Controller ++
TAKEAWAYS
85HOW SMART USE CASES DRIVE WEB DEVELOPMENT©2010 Capgemini. All Rights Reserved
Coding
� Implement task pattern
� Implement task management
� Modeling provides for model driven
development
Testing
� Smart use cases allow for automated testing
� Great code coverage on all layers
� Mock actual task environment
� Run tests automated in nightly builds
TAKEAWAYS
www.accelerateddeliveryplatform.com
WWW.SMARTUSECASE.COM
www.sanderhoogendoorn.com
www.smartusecase.com
@aahoogendoorn
REFERENCES AND QUESTIONS