3

I haven't come across this issue before and can't find it in my Schaum's Outline UML book and was wondering if someone here could help.

I'm making a use case diagram for e-commerce, and in it I want to describe that in order to add a book to your shopping basket, you have to either search products (using the websites search engine) or browse products (using navigation).

But the thing is that it can be either one, and not both.

Is there a way to show that adding a product to the basket needs to include either this or that? Because otherwise it would look like it needs to include both.

Or should I join the two use cases (search products and browse products) into one?

  • The <<extend>> relationship depicts conditional execution of use-cases. The other choice is <<include>> which means it is always executed. You'll notice that even in the case of a typical extend, there is nothing denoting when it will be extended. That is covered in the use-case description text. If it can only be either one or the other then your use-case text description should cover that, not the use-case diagram. If you want to go off on a tangent and do useless work then I'm sure there's a way to use metadata to depict what you want. – Dunk Apr 11 '13 at 18:24
  • 1
    Okay I can explain it in the use case specification and point to both use cases from 'add to basket'. Thanks – TheNewBlack Apr 11 '13 at 18:28
  • How about using subsystem block but mark it as "OR" stereotype rather than "subsystem" – nikita Nov 8 '13 at 11:47
1

The most important is that it is clear from the use case description that a choice must be made between the search and the browse functionality.

In your diagram, the 'add to basket' use case should <<include>> both the 'search products' and 'browse products' use cases (assuming that the choice for searching or browsing is made from the 'add to basket' use case). If you really want to show that those included use cases are mutually exclusive, you can add a UML constraint { mutually exclusive } linked to the inclusion arrows, but that is completely optional.

  • thanks for the reply, never seen that constraint used before. learned something new – TheNewBlack Apr 12 '13 at 8:00
  • constraints aren't used that often, especially not in use case diagrams, where the important content is in the descriptions anyway. – Bart van Ingen Schenau Apr 12 '13 at 8:03
1

Yes, it is possible in UML.

  • Let us name alternatives A1 and A2.
  • They should have some common functionalities, or they wouldn't be interchangeable. Find those.
  • Make a common interface or abstract class for the alternatives. Let us name it A.
  • Use reference to A instead of references to A1 or A2.
 A a;

As the common type is abstract, you have a guarantee, that you'll use A1 orA2.

a=new A1();

or

a=new A2();

Look at https://stackoverflow.com/a/21137565/715269 for a diagram

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.