I have a sequence diagram, and I would like to create a class diagram from it.
This is the sequence diagram:
I'm struggling with classes operations (which class should I give what operations)
You can derive the class from the life line. Each is an instance of a class. With the used notation you can say that the title corresponds to the class name directly. The actor is some informal compromise and is not a class.
The messages towards a life line correspond to operations of the class. E.g. ViewBookForm has onClick().
In any case you can pinpoint only those operations you have in the diagram. And you can't find out the atributes. So your classes will be skeletons only.
Related
What are differences between instance and role in terms of UML (class diagram, object diagram, sequence diagram) ?
Roles (e.g., in a composite structure diagram) are another representation of properties shown in a class diagram. On the composite structure diagram one can show a particular configuration of which subtype is used for each property. A role name and type is not underlined.
In contrast, an instance specification represents a partial or complete instance. On a class diagram, an instance specification can show values for every property, including links to other instance specifications. An instance specification name and type is underlined on the diagram.
These diagrams look pretty similar, but the intent is different. Instance specifications show instances at one flat level. Composite structure diagrams show internal configurations within a class (or other context, such as a collaboration) and can nest to any level.
Role names are found at the opposite end of connectors and denote the name of the instance by which a class references it.
CollaborationRoles are used to represent different implementations (or aspects) of a single use case.
Users (and systems) play roles of Actors.
Instances as described in UML 2.5:
InstanceSpecifications represent instances of Classifiers in a modeled system. They are often used to model example configurations of instances. They may be partial or complete representations of the instances that they correspond to.
In a UML class diagram, is it technically correct to have two possible compistion relationships leading to one class?
I.E. I have an inventory class, which has a composition of the inventory class. I want to have the same relationship but with a container class taking the place of the inventory.
So, can I have two compositions, or do I need to turn these into aggregations?
You can have as many composite associations as you like on the class level. But each instance can only be part of one composition at a specific moment in time.
UML superstructure says:
If the whole has aggregationKind = composite then the part can be included in at most one composite at a time
This article I wrote tries to explain the difference: UML Composition vs Aggregation vs Association
Any number of composition association can lead to one class of course. If instance of composed class is composed of instances of more types for example.
Is there a way to depict dependency of methods of the same class in a class diagram. I have a class which has two methods :-
getArrayListOfLotteries()
removeDuplicateElementsOftheList(ArrayList listOfLotteries)
when you call getArrayListOfLotteries which is a public method , the private method removeDuplicateElementsOftheList would be called before the former returns. Is there a way to somehow show this in a class diagram ?
In the structural class diagram you can show that getArrayListOfLoterries is public and that removeDuplicateElementsOftheList is private or protected (see http://www.uml-diagrams.org/visibility.html)
Then you can use e.g. behavioral sequence diagram to show that getArrayListOfLoterries calls removeDuplicateElementsOftheList by drawing overlapping execution or sending a message to self (see http://www.uml-diagrams.org/sequence-diagrams.html#execution)
In my opinion it is perfectly legal to combine both aspects (both kinds of diagram) into one combined diagram. As far as I remember specification does not disallow it (TODO: link some proof)).
Pure class diagram does not have features to display more complex behavioral aspects (TODO: give some examples of less complex vs. more complex aspects)
How do i model a call to a static method in a class diagram ? Can someone show me a link to a class diagram that has done that?
for example there's a class called Animal. and i have another class called Vertibrates, and it has a method which is static (and this is the only method in that class). My Animal class will be using this static method of the class Vertibrate. Therefore how can i model it in class diagram ?
You don't. Well, not in a class diagram at least. Instead, you should use sequence chart diagrams to express method calls (whether static or dynamic).
You can't model the call directly in a class diagram (as #Imontrieux says), but you can model the relationship (i.e., that Animal uses (calls) static methods in Vertibrate; BTW, the correct spelling is Vertebrate), which I suspect is actually what you meant.
You use a UML dependency for this, not an association (since the latter are for associations between instances of the classes at each end)--- see How to show usage of static methods UML Classdiagram.
Great question. One thing the GoF do in Design Patterns is used notes to demonstrate intended uses. For example, from the section on the Command Pattern:
Command Pattern
While #user1315906 is technically correct that you don't model such things in Class Diagrams, but rather in Use Case or Sequence Diagrams, if it makes sense to note how something is intended to be used in a Class Diagram, you can use a note :)
In a UML diagram when you create an instance of a subclass do you usually include the implicit construction of the superclass prior to the sub class constructor?
I usually wouldn't include it. The purpose of the UML sequence diagram is to show what happens between components. It shouldn't be read isolated from other parts of a design, so if a reader is unsure about what any of the components is (i.e. an instance of the subclass and the superclass), he or she should look into the - hopefully - accompanying class diagram.
sequence just shows the sequence of the logic of the module in question. Do you feel there is need to identify which method is truly being called? Also I would guess that the purpose of having a parent clas have a reference to a subclass is that until runtime you won't know which subclass is actually being referred to. If this is not the case, then should the concrete subclass be referred to explictly? does the method being called whether on the subclass or parent class alter the sequence in some way?