0

Here is a kata for the Bowling Game problem. Slide 9 (below) shows a design diagram. But its not obvious to me which box is a class and which is a property or method from the makeup of the boxes themselves.

enter image description here

Is this a UML object diagram and if so, isn't there a better way to express class properties as part of the class as a whole? I realise +score(): int is a method but what about 'Frame'?

The Frame box looks the same as the Game box. In the final solution only a Game class is created and Frame is only really used as the number of times to loop within the scoring algorithm

I realise this is quite a specific case but I'm interested in how the diagram is used to model the problem. As illustrated in this question, I immediately think 'Frame' is a class name when looking at the diagram.

  • 1
    Yes, this is a fairly standard UML class diagram describing four classes Game, Frame, TenthFrame and Roll. If the solution code does not use these classes, we can infer that this diagram does not model that solution. But that's not surprising – designs change, and complex designs can be simplified. – amon May 31 '15 at 17:15
  • Thanks. Its confusing as in the set of slides, they repeat the same slide once the solution has been explained. However, perhaps being at the presentation would have made this obvious. Feel free to make your comment an answer and I will accept. – codecowboy May 31 '15 at 17:23
2

The diagram is a UML class diagram, using the notations for classes, associations (with multiplicities), and generalization. Although the notation is using perfectly valid UML, it appears to be in one of the less complete notations that Martin Fowler describes as UML as Notes or UML as Sketch. It's using the symbology of the language correctly, but omitting details to make it easier to read. Such a notation is useful to communicate between people, but wouldn't support something like forward engineering from models to code.

In the diagram that you presented, each of the boxes is a class. There is a Game class with public methods roll(int) and score(), a Frame class with public method score(), and a Roll class with a private member variable pins. There's also a TenthFrame class that inherits from Frame.

Some details about the members of classes have been omitted from the diagram. For example, there is an association relationship between Game and Frame - Game knows of 10 instances of Frame. The use of the association relationship implies that Game not only knows about the interface of Frame (a dependency on Frame), but also maintains 10 instances as part of the object. Although you could show this explicitly by adding a member variable to Game that shows an array of 10 Frame objects, this is simply duplicating what the association relationship is already showing you. There is a similar relationship between Frame and Roll - a Frame has at least 1 and no more than 2 Rolls.

Looking through the slides that you linked to, you are right that the final solution doesn't appear to use anything other than a Game class (at least that I can see looking through the code in the slide deck). When following the principles of Agile Modeling, there would be a Single Source of Information, meaning those models would have likely been thrown away after the code was written and they have outlived their usefulness.

What it looks like happened is that the authors used UML (since it's a familiar and standardized notation) to walk through the problem and explain how it was decomposed. However, as they were writing code, they decided that they didn't need all of the classes to realize the simplest implementation. However, the act of modeling improved their understanding of the problem and the rules associated with it, but may not have driven the implementation.

0

Yes, it's kind of UML. It seems to me that this diagram shows the number of potential runtime instances in addition to the releations between classes. Kind of entity relationship diagram and class diagram rolled into one picture. Works only if entities and classes have a 1:1 relationship.

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.