So, you have a feature to write. Now what? Do you start coding right away and hope for the best? Hopefully not. Here’s an example of using a Universal Modeling Language (UML) Sequence Diagram to plan a feature.
In this example, User
calls the create()
method on Post
, which in turns calls the send()
method on the Messenger
class. The dotted line is called the object’s Lifeline. The part of the Lifeline that is wider, is where the object is active.
What are the benefits of a sequence diagram? It turns the focus from the objects themselves to the messages that pass between them. You can see what public interfaces you’ll need to implement. As Sandi Metz writes in her book, Practical Object-Oriented Design in Ruby, this process can also reveal ‘hidden objects’ – object you didn’t know you needed. If you do TDD, you also know what tests to write. What happens if you make a mistake? Just fix the diagram. It’s a lot cheaper than fixing code.