1

Can requirements be expressed in class-diagrams?

For example:

A student can enroll in a class. There are different classes. Some classes have dependencies, e.g. you can't go to Spanish III before you went to Spanish II and Spanish I.

How to model that?

6
  • Sharing your research helps everyone. Tell us what you've tried and why it didn't meet your needs. This demonstrates that you've taken the time to try to help yourself, it saves us from reiterating obvious answers, and most of all it helps you get a more specific and relevant answer. Also see How to Ask
    – gnat
    Commented Mar 24, 2020 at 9:10
  • Don't be scared by comments. The above is from a moderator and generally a valid statement (it's not an answer). You'll get used to certain habits at SO over time...
    – user188153
    Commented Mar 24, 2020 at 11:00
  • @qwerty_so, to be clear, gnat is not a moderator. He’s more of a glitch in the system that’s useful enough that the real mods choose to leave him in place rather than “fix the bug” by banning him.
    – David Arno
    Commented Mar 24, 2020 at 20:19
  • 1
    @DavidArno Well to us lower ones that does not make a difference ;-) I saw hin in so many posts that I just assumed him to be a mod...
    – user188153
    Commented Mar 24, 2020 at 21:19
  • 1
    Usually requirements are expressed as user stories. Sometimes the problem is clear enough to start writing classes but we usually want to keep that conceptual at the beginning. (Look up CRC cards). Class Responsibility Collaborator cards are a way to think about what classes you may need before writing the details of their implementations.
    – John Douma
    Commented Mar 25, 2020 at 2:19

2 Answers 2

3

No, most requirements can not be fully expressed in a class diagram.

A class diagram shows the static structure of how classes are related to each other, but many requirements also have a dynamic aspect to them. However, requirements do drive the structure of the class diagram.

For example, to be able to fulfil the requirement that a Student must have followed the Class "Spanish I" before being allowed to enroll in "Spanish II", the class diagram must show an optional relation of Class with itself to record the possible prerequisites for a class.

1

Requirements can be expressed either via requirement elements you can create on your own with a profile (there are already a couple of profiles offering that kind of element). However, more quickly you can just add constraints derived from requirements and plaster them in your class diagram - linked up to where they shall belong. A constraint can be represented as a {note with text in curly brackets}. Eventually you can stereotype that with <<pre-condition>>, <<post-condition>> or <<invariant>>.

With respect to the requirements you listed: they are related to runtime and are a better fit for use cases. The above is more for things like "student names may not exceed 20 chars or the like.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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