October 12, 2006

...Learn TDD with Codemanship

Use Cases & Scenarios

A common source of confusion in analysis and design centres around the difference between a use case and a scenario. Quite often I find the terms being used interchangeably - indeed, now and again I'll catch myself saying "use case" when I really mean "scenario".

I want to try and clear things up a little, if I can. In the UML metamodel, the difference is very clear. A use case is a kind of classifier; that is, it describes a set of use case scenarios. The relationship between use case and scenario is the same kind of relationship that exists between classes and instances (objects).



In the example above, Clarence is an instance of the class Lion. In much the same way, a scenario like Feed A Pork Chop To Clarence could be an instance of the use case Feed Lion. UML currently doesn't offer any notaton for modeling use case instances (scenarios), so I've made one up that I hope makes some sense.



Of course, this example would be a little too specific for your average use case design specification, but we could generalise it a little bit - in much the same way that we can generalise object diagrams and sequence diagrams by parameterising our scenario data and using anonymous instances.

Actors in UML are also classifiers, so we could apply the same principle to actors participating in use case scenarios. In the example below, an anonymous instance of Keeper feeds the lion.



We can relate objects to classes by looking at the members - attributes and operations - that an object has. We could surmise that three different objects that share the same attributes and operations are of the same class. We might also be able to surmise that three scenarios that share the same starting point and set out with the same functional goal are instances of the same use case.

So what's this got to do with the price of onions? Well, firstly it helps me to picture how use cases and scenarios are related in a more explicit and tangible way. But it can also help to use my made-up notation to discuss scenarios at the whiteboard with customers and testers. Frankly, I think UML 2.0 should have included something along these lines. But then, they didn't ask me...

There we are; clear as mud :-)
Posted 14 years, 2 months ago on October 12, 2006