Activity diagrams -Making choices

Activity diagrams allow you to make choices using a combination of a special symbol and a guard. You may not familiar with the term “guard” so we shall explore its meaning in this section. The diagram below shows a simple choice.

The diamond shape represents a decision. This can be a simple true/false one or possibly a set of if/then/else statements. It can even be used to represent switch/case statements. What we mean by this is that a diamond can have two or more choices coming from it. These can then lead to any other symbol that can be used in activity diagrams.

The guard (the text in [] brackets) specifies what conditions must be met for that path to be followed. Like all selection in programming and design this must evaluate to true or false. In fact that is the only real requirement on the guard. If the guard evaluates to true then flow will go along that link. In the example above if the dog is dirty (or if dog is dirty evaluates to true) then we will wash the dog. If the dog is clean then we will simply just play with the dog.