HOW SMART USE CASES DRIVE WEB DEVELOPMENT
Sander Hoogendoorn
Principal Technology Officer Capgemini
SANDER HOOGENDOORN
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
[Link] [Link] Twitter / LinkedIn : aahoogendoorn
HOW 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
HOW 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
HOW SMART USE CASES DRIVE WEB DEVELOPMENT
2010 Capgemini. All Rights Reserved
REQUIREMENT TECHNIQUES COMPARED
User stories, huge cases and smart use cases
USER STORIES APPLES AND PEARS
Often too unstructured Unsuitable in complex environments
HOW SMART USE CASES DRIVE WEB DEVELOPMENT
2010 Capgemini. All Rights Reserved
COMPLEX IT LANDSCAPES
HOW SMART USE CASES DRIVE WEB DEVELOPMENT
2010 Capgemini. All Rights Reserved
HUGE CASES
Hard to build, impossible to test
HOW SMART USE CASES DRIVE WEB DEVELOPMENT
2010 Capgemini. All Rights Reserved
DIFFERENT LEVELS OF USE CASES
Cloud level Selling products Kite level
Products High summary
Summary
Sell book Sea level User goal
Fish level
Search book Insert orderline
Sub-function
Clam level
Too low
HOW SMART USE CASES DRIVE WEB DEVELOPMENT
2010 Capgemini. All Rights Reserved
DIFFERENT LEVELS OF USE CASES
HOW SMART USE CASES DRIVE WEB DEVELOPMENT
2010 Capgemini. All Rights Reserved
10
DIFFERENT LEVELS OF USE CASES
Traditional use cases
Only user goal level use cases Use cases as they are intended A single use case describes a single elementary business process Differ in granularity too much Law of Large Numbers does not apply
Estimate Hard Easy Format Traditional use cases Textual Smart use cases Visual
Granularity
Different
Unified
Smart use cases
User goal and sub function level use cases Good unit of work and estimation A single elementary business process is modeled in a single use case diagram A single user goal level use case + auxiliary use cases at sub-function level Very similar granularity
Reuse Incidental Normal Unit of work Lousy Good
Traceability
Possible
Normal
Testability
Poor
Good
HOW SMART USE CASES DRIVE WEB DEVELOPMENT
2010 Capgemini. All Rights Reserved
11
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
HOW SMART USE CASES DRIVE WEB DEVELOPMENT
2010 Capgemini. All Rights Reserved
12
SMART USE CASES
A YAGNI approach to requirements
YAGNI. YOU AINT GONNA NEED IT
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
HOW SMART USE CASES DRIVE WEB DEVELOPMENT
2010 Capgemini. All Rights Reserved
14
AGILE REQUIREMENTS - APPROACH
Cloud Level Kite Level Sea Level Fish Level
B D
A B C
Hierarchical Processes
C D
E D D F
Project Scope
Hierarchical Processes
Use Cases
Smart Use Cases
Chronological Processes
HOW SMART USE CASES DRIVE WEB DEVELOPMENT
2010 Capgemini. All Rights Reserved
15
CLOUD LEVEL
HOW SMART USE CASES DRIVE WEB DEVELOPMENT
2010 Capgemini. All Rights Reserved
16
KITE LEVEL
HOW SMART USE CASES DRIVE WEB DEVELOPMENT
2010 Capgemini. All Rights Reserved
17
IDENTIFYING SUB-FUNCTION LEVEL USE CASES
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)
HOW SMART USE CASES DRIVE WEB DEVELOPMENT
2010 Capgemini. All Rights Reserved
18
MODELING SMART USE CASES
HOW SMART USE CASES DRIVE WEB DEVELOPMENT
2010 Capgemini. All Rights Reserved
19
MODELING SMART USE CASES SEA AND FISH LEVEL
HOW SMART USE CASES DRIVE WEB DEVELOPMENT
2010 Capgemini. All Rights Reserved
20
DESCRIBING USE CASES SEA AND FISH LEVEL
HOW SMART USE CASES DRIVE WEB DEVELOPMENT
2010 Capgemini. All Rights Reserved
21
SMART USE CASES
Stereotypes
SMART USE CASE STEREOTYPES
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
HOW SMART USE CASES DRIVE WEB DEVELOPMENT
2010 Capgemini. All Rights Reserved
23
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
HOW SMART USE CASES DRIVE WEB DEVELOPMENT
2010 Capgemini. All Rights Reserved
24
SMART USE CASE DRIVEN ARCHITECTURE
An overview
USING REFERENCE ARCHITECTURES
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
HOW SMART USE CASES DRIVE WEB DEVELOPMENT
2010 Capgemini. All Rights Reserved
26
Presentation
Pages UserControls Panels
Process
Use cases Workflow
Domain
Domain objects / Entities Factories / Repositories Enums / Value objects / Smart references [Mapping]
Data / Services
Table Gateways Queries [Mapping]
Outside world
Database
HOW SMART USE CASES DRIVE WEB DEVELOPMENT
2010 Capgemini. All Rights Reserved
27
Presentation
Pages UserControls Panels
Process
Use cases Workflow
Domain
Domain objects / Entities Factories / Repositories Enums / Value objects / Smart references [Mapping]
Data / Services
Service gateways Service locators [Mapping]
Exact Outside world
SAP
BizTalk
Java Services / ESB
HOW SMART USE CASES DRIVE WEB DEVELOPMENT
2010 Capgemini. All Rights Reserved
28
Presentation
Service contracts Operation contracts Data contracts
Process
Use cases Services
Domain
Domain objects / Entities Factories / Repositories Enums / Value objects / Smart references [Mapping]
Data / Services
Table Gateways / Service Gateways Queries / Service Locators [Mapping] Exact SAP BizTalk Java Database Services / ESB
Outside world
HOW SMART USE CASES DRIVE WEB DEVELOPMENT
2010 Capgemini. All Rights Reserved
29
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
HOW SMART USE CASES DRIVE WEB DEVELOPMENT
2010 Capgemini. All Rights Reserved
30
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
HOW SMART USE CASES DRIVE WEB DEVELOPMENT
2010 Capgemini. All Rights Reserved
31
SMART USE CASE DRIVEN ARCHITECTURE
Introducing the Task Pattern
Presentation
Pages UserControls Panels
Process
Use cases Workflow
Domain
Domain objects / Entities Factories / Repositories Enums / Value objects / Smart references [Mapping]
Data / Services
Table Gateways Queries [Mapping]
Outside world
Database
HOW SMART USE CASES DRIVE WEB DEVELOPMENT
2010 Capgemini. All Rights Reserved
33
SMART USE CASES IN CODE
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
HOW SMART USE CASES DRIVE WEB DEVELOPMENT
2010 Capgemini. All Rights Reserved
34
SMART USE CASES IN CODE
HOW SMART USE CASES DRIVE WEB DEVELOPMENT
2010 Capgemini. All Rights Reserved
35
TASK PATTERN
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!
HOW SMART USE CASES DRIVE WEB DEVELOPMENT
2010 Capgemini. All Rights Reserved
36
TASK PATTERN
HOW SMART USE CASES DRIVE WEB DEVELOPMENT
2010 Capgemini. All Rights Reserved
37
TASK PATTERN IN PRACTICE
HOW SMART USE CASES DRIVE WEB DEVELOPMENT
2010 Capgemini. All Rights Reserved
38
TASK PATTERN IN PRACTICE RUNNING A USE CASE
HOW SMART USE CASES DRIVE WEB DEVELOPMENT
2010 Capgemini. All Rights Reserved
39
TASK PATTERN
HOW SMART USE CASES DRIVE WEB DEVELOPMENT
2010 Capgemini. All Rights Reserved
40
TASK PATTERN START FIRST USE CASE
HOW SMART USE CASES DRIVE WEB DEVELOPMENT
2010 Capgemini. All Rights Reserved
41
TASK PATTERN START SECOND USE CASE
HOW SMART USE CASES DRIVE WEB DEVELOPMENT
2010 Capgemini. All Rights Reserved
42
TASK PATTERN WEB PAGE WITH SECOND USE CASE
HOW SMART USE CASES DRIVE WEB DEVELOPMENT
2010 Capgemini. All Rights Reserved
43
TASK PATTERN POST CONDITIONS SECOND USE CASE
HOW SMART USE CASES DRIVE WEB DEVELOPMENT
2010 Capgemini. All Rights Reserved
44
TASK PATTERN CONTINUE FIRST USE CASE
HOW SMART USE CASES DRIVE WEB DEVELOPMENT
2010 Capgemini. All Rights Reserved
45
TASK PATTERN WEB PAGE WITH FIRST USE CASE
HOW SMART USE CASES DRIVE WEB DEVELOPMENT
2010 Capgemini. All Rights Reserved
46
TASK PATTERN POST CONDITIONS FIRST USE CASE
HOW SMART USE CASES DRIVE WEB DEVELOPMENT
2010 Capgemini. All Rights Reserved
47
SMART USE CASE DRIVEN ARCHITECTURE
Task management with the Manager-Provider Pattern
MANAGER-PROVIDER PATTERN
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
HOW SMART USE CASES DRIVE WEB DEVELOPMENT
2010 Capgemini. All Rights Reserved
49
MANAGER VALIDATIONMANAGER
HOW SMART USE CASES DRIVE WEB DEVELOPMENT
2010 Capgemini. All Rights Reserved
50
INTERFACE
HOW SMART USE CASES DRIVE WEB DEVELOPMENT
2010 Capgemini. All Rights Reserved
51
MANAGER INITIALIZATION (USING DEPENDENCY INJECTION)
HOW SMART USE CASES DRIVE WEB DEVELOPMENT
2010 Capgemini. All Rights Reserved
52
CONFIGURATION OF IMPLEMENTATION
HOW SMART USE CASES DRIVE WEB DEVELOPMENT
2010 Capgemini. All Rights Reserved
53
MANAGER - EXECUTING METHODS
HOW SMART USE CASES DRIVE WEB DEVELOPMENT
2010 Capgemini. All Rights Reserved
54
CLIENT CALLING METHODS
HOW SMART USE CASES DRIVE WEB DEVELOPMENT
2010 Capgemini. All Rights Reserved
55
MANAGER-PROVIDER PATTERN
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!
HOW SMART USE CASES DRIVE WEB DEVELOPMENT
2010 Capgemini. All Rights Reserved
56
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
HOW SMART USE CASES DRIVE WEB DEVELOPMENT
2010 Capgemini. All Rights Reserved
57
GENERATING CODE FROM SMART USE CASES
An introduction to pragmatic model driven development
Existing Applications
1. Map your business processes to smart use cases
Smart use cases
User interface specification
Software Architecture
5. Finalize your application
Forms
Tobago MDA Specifications Domain Model
4. Generate your code using a text template engine
Use cases
Frameworks Domain objects
Business models
Data / Service classes
2. Set up your domain model
Test scenarios Databases
3. Establish your software architecture(s)
2010 Capgemini. All Rights Reserved
HOW SMART USE CASES DRIVE WEB DEVELOPMENT
59
MODEL DRIVEN DEVELOPMENT TEMPLATE ENGINES
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
HOW SMART USE CASES DRIVE WEB DEVELOPMENT
2010 Capgemini. All Rights Reserved
60
MODEL DRIVEN DEVELOPMENT - TEMPLATE ENGINES
Properties can be used in templates Template engine knows (part of) the UML meta model
HOW SMART USE CASES DRIVE WEB DEVELOPMENT
2010 Capgemini. All Rights Reserved
61
MODEL DRIVEN DEVELOPMENT - TEMPLATES
HOW SMART USE CASES DRIVE WEB DEVELOPMENT
2010 Capgemini. All Rights Reserved
62
GENERATE MANY THINGS E.G. TABLE CREATE SCRIPTS
HOW SMART USE CASES DRIVE WEB DEVELOPMENT
2010 Capgemini. All Rights Reserved
63
GENERATING CODE
A quick example
A SIMPLE SMART USE CASE MODEL
uc Manage Customer
search Select Customer
incl ude
master detail Manage Customer Site Administrator (from A ctors) extend define Define Contact
HOW SMART USE CASES DRIVE WEB DEVELOPMENT
2010 Capgemini. All Rights Reserved
65
A SIMPLE DOMAIN MODEL
class [Link] business class Cust omer + + + + + + Name: string Address: string Postcode: Postcode City: string Country: SmartRef Website: Url [0..1] + * + + + business class Cont act Name: string Email: Email [0..1] Phone: PhoneNumber [0..1] Department: Departments
enumeration Depart ments Sal es Purchasing Helpdesk Management
HOW SMART USE CASES DRIVE WEB DEVELOPMENT
2010 Capgemini. All Rights Reserved
66
USING TOBAGO MDA
HOW SMART USE CASES DRIVE WEB DEVELOPMENT
2010 Capgemini. All Rights Reserved
67
GENERATED CODE IN [Link]
HOW SMART USE CASES DRIVE WEB DEVELOPMENT
2010 Capgemini. All Rights Reserved
68
GENERATED CODE IN SILVERLIGHT
HOW SMART USE CASES DRIVE WEB DEVELOPMENT
2010 Capgemini. All Rights Reserved
69
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
HOW SMART USE CASES DRIVE WEB DEVELOPMENT
2010 Capgemini. All Rights Reserved
70
UNIT TESTING SMART USE CASES
Unit testing at the right level
Presentation
Pages UserControls Panels
Process
Use cases Workflow
Domain
Domain objects / Entities Factories / Repositories Enums / Value objects / Smart references [Mapping]
Data / Services
Table Gateways Queries [Mapping]
Outside world
Database
HOW SMART USE CASES DRIVE WEB DEVELOPMENT
2010 Capgemini. All Rights Reserved
72
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
HOW SMART USE CASES DRIVE WEB DEVELOPMENT
2010 Capgemini. All Rights Reserved
73
UNIT TESTING SMART USE CASES
Test methods from Task Pattern
Run method
Validate outcome
HOW SMART USE CASES DRIVE WEB DEVELOPMENT
2010 Capgemini. All Rights Reserved
74
UNIT TESTING SMART USE CASES
Test methods that interact with domain
Set up (in)valid domain object
Run method from use case Validate outcome
HOW SMART USE CASES DRIVE WEB DEVELOPMENT
2010 Capgemini. All Rights Reserved
75
UNIT TESTING SMART USE CASES
Introducing a light weight smart use case unit testing framework
A LIGHTWEIGHT SMART USE CASE UNIT TESTING FRAMEWORK
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
Dont 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
HOW SMART USE CASES DRIVE WEB DEVELOPMENT
2010 Capgemini. All Rights Reserved
77
CONFIGURING TEST ENVIRONMENT
HOW SMART USE CASES DRIVE WEB DEVELOPMENT
2010 Capgemini. All Rights Reserved
78
TEST MANAGER LOGGING EVENTS
HOW SMART USE CASES DRIVE WEB DEVELOPMENT
2010 Capgemini. All Rights Reserved
79
MOCKING ENVIRONMENT LOGGING EVENTS
HOW SMART USE CASES DRIVE WEB DEVELOPMENT
2010 Capgemini. All Rights Reserved
80
TEST MANAGER QUERYING EVENTS
HOW SMART USE CASES DRIVE WEB DEVELOPMENT
2010 Capgemini. All Rights Reserved
81
TEST MANAGER RUNNING TESTS
Test methods that interact with domain Set up (in)valid domain object
Run method from use case
Validate outcome
HOW SMART USE CASES DRIVE WEB DEVELOPMENT
2010 Capgemini. All Rights Reserved
82
TAKEAWAYS
TAKEAWAYS
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 ++
HOW SMART USE CASES DRIVE WEB DEVELOPMENT
2010 Capgemini. All Rights Reserved
84
TAKEAWAYS
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
HOW SMART USE CASES DRIVE WEB DEVELOPMENT
2010 Capgemini. All Rights Reserved
85
[Link]
[Link]
REFERENCES AND QUESTIONS
[Link]@[Link] [Link] [Link] @aahoogendoorn