3

In a class diagram, how do I know what methods to add? I’m not sure what the connection is between methods and other (i.e. Activity and User Case) diagrams. My guess is that methods can come from Sequence Diagrams, but then I’m not sure how sequence diagrams relate to the Activity and User Case diagrams. I’m trying to understand how all the design diagrams fit together. How do diagrams connect or flow into each other? I’m presuming they’re related.

2
  • 1
    "how do I know what class methods to add" - if it's a yet-to-be created system and you're doing modeling (= working out what the code is going to be like), then there's no preexisting list of methods that you can pull from. You need to invent them. That's the whole point; you're creating something new, and you're trying to work out how to satisfy system requirement or business needs using pictures. Sequence diagrams show a sequence of interactions between several objects, so there will be methods from different objects in them; you have to invent these objects (and their methods) first. Jan 26 at 17:41
  • Hi @DocBrown, I mean the arbitrary methods inside the class box of classes in a class diagram.
    – ltrainpr
    Jan 27 at 14:55

2 Answers 2

4

The Use Case and Activity diagrams are high level things showing how the users (Actors) are going to interact with the system. At this stage there will be no classes or methods.

Class Diagrams and Sequence Diagrams are the details of what's going on in your system to implement the high level stuff.

You can't really have a sequence diagram without the methods. But drawing one might reveal that you are missing some methods that you need to create.

Which methods should you add? The ones you need! You are allowed to simplify diagrams by leaving bits out. But methods are things that you realise that you need when you start thinking how the classes will interact with each other.

Ultimately, UML doesn't do the design work for you. It gives you a way to illustrate the design in pictures, not (just) text in a design document.

4
  • 2
    "Ultimately, UML doesn't do the design work for you. It gives you a way to illustrate the design in pictures" - @ltrainpr, that sentence is your answer. UML does not design things. Humans do the design work, and then record those designs in UML. Jan 26 at 18:56
  • Ok, so what I'm understanding is that UML is just the representation of the design you've invented. It's not a tool to help you come up with a design. So does the design come from spikes and pseudo code? Or is it more trial and error that's passed between engineers?
    – ltrainpr
    Jan 27 at 15:06
  • @ltrainpr: there are a lot of books written on how software design can be accomplished, with several different schools of thought. Hence, it is pretty hard to give you a sufficient answer here in a comment box. You may start with this online book "How to Design Programs". Spoiler: there is no UML inside. See also the Wikipedia article about it.
    – Doc Brown
    Jan 27 at 15:42
  • @ltrainpr The design comes from one or more people sitting down and working out what the system is going to do. Once they have a high-level view (e.g. UML Use Cases), they can break it up into software modules, and then down to classes and methods. Nothing does it for you. It's people thinking through the problem. UML is a way of drawing your thoughts as pictures.
    – Simon B
    Jan 27 at 21:43
0

In a class diagram, how do I know what class methods to add?

That depends entirely on why you are creating the diagrams in the first place.

If you are creating the diagram with the purpose to generate code from it, then you need to add all the methods of the class to it. Otherwise, the code generator doesn't know it needs to generate those methods.

If you are creating the diagram to explain something from your design or your code to someone else, then you should only add the details (including methods) that are needed to get the point you want to maker across.

1
  • I would add to your last paragraph that "to explain something from your design" usually means "to explain something from your code".
    – Doc Brown
    Jan 26 at 14:40

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.