2
votes

I am trying to understand new piece of project. I am drawing UML class diagrams, but there is something missing for me in these diagrams: the creation of objects. What a traditional UML diagram can depict is how these classes are related to each other and how instances of these classes are related to other objects of other classes, but that is in the moment when they are already created. Sometimes it is not that obvious who creates who, sometimes it is totally misleading. For example objects of class A may create object of class B, but that A object just returns this B object and gives it to somebody else and doesn't hold any reference to it. And sometimes it holds (a reference or pointer). Sometimes it matters for the reader. So in fact there are two types (pieces) of information: holding and creating. I came up with my own way of visualizing this, but maybe there is something standard here? What do you think? And I don't have UML Object diagram in mind, that is not something very helpful when reading C++ or Java code and trying to understand the relation of classes and objects. And not sequence diagram also, that's a different kind of beast.

2
Do you use a specific software methodology in software development?Gholamali-Irani
Hm... I don't understand your question. What exactly do you mean?YotKay
For example : RUP based methodologies, or Agile based or Scrum or something else.Gholamali-Irani
Yeah, draw something useful. Maybe in 100 years it will be worth 1 million bitcoins. Read what Euclid said to Ptolemy about maths. Design is the same.qwerty_so
I'm surprised about your apparent unwillingness to consider sequence diagrams as they are an excellent way of documenting what happens in your program. And this is something I often do when trying to understand complex C++/Java code: create classes using class diagrams, create activities for local operations/methods, create sequence diagrams for using an operation from another class, combine fragments when creating a global overview of the system.CharlesRivet

2 Answers

1
votes

If you want to stick to class diagrams, you can use the «create» usage dependency from UML Standard Profile (chapter 22 of UML 2.5 specs).

«Create» | Usage | A usage dependency denoting that the client classifier creates instances of the supplier classifier.

So e.g. here A creates an instance of B, and C just has a reference to B.

enter image description here

1
votes

A type of UML diagrams show only one particular view of your system by abstracting the other aspects of a system. For example, a class diagram shows only the static aspect of the system, but not the dynamic behavior such as:

At what time an object was created

The central ideas of modeling a system is trying to deal with (or focus on) an aspect at a time, and at the same time to eliminate the complexity by forget about the other aspects of a system.

In this case, "creating an object at a particular time by who (another object)" should be dealt with behavior view, thus, we can use a sequence diagram to modeling the dynamic behavior:

enter image description here

You can see the Dimension of a sequence diagram in the Figure:

  1. Horzontally, Objects Lifecycle
  2. Vertically, Time

You might then be interested, how I can relate these models together? Will there be any inconsistencies among them? Right! if you are puzzling about this, you are in the right track!

Look! models are inter-connected each other, take an example, you can create a use case, and a use case can be detailed with a number of scenarios, then.. each scenario can be modeled by a sequence diagram, and the sequence diagram giving you the hints of what objects (and what operations and attributes in it) you need to build your systems, right?

enter image description here