Which relationship line to use in a UML class diagram? - uml

In a UML class diagram I want to show the relationship between two classes where the second class is the type of a class variable in the first.
I've looked here but am still unsure which relationship I should be using.
I think it may be the Dependency relationship but I am unsure.
Which should I be using?

It sounds like a composition(has a) but would need to hear more about your diagram.

Related

UML class diagrams: References to instances?

Some classes in my class diagram need to reference specific instances of other classes or themselves. Should I just model those the same way i would in an object diagram or is there a better option? In general: Can one combine class and object diagrams, since object diagrams are themselves class diagrams?
thanks!
UML2 introduced Composite Structure Diagram exactly to solve this issue.
In a Composite Structure Diagram you can show classifiers (e.g. Classes) together with theirs internal composition in terms of instances.
This way you can specify exactly which instances are linked to your objects.
See this article for a good explanation.
I agree with #Thomas Killian : you want to mix two different representations.
On the class diagram you will be able to show cardinalities, but not instances relationships. It seems your List class is not a simple list but a chain / linked list.
A ListElement is in fact part of a LinkedList. Two predecessor and successor attributes themselves of type ListElement (or how you wish to call this class, the node role could be noted) will be enough to suggest the behavior. As an attribute has a 1:1 cardinality with the encapsulating class, this respects what you wish to model. Renaming the list class would be a hint for the diagram reader.
Take a look at the Java Linked List source if you want some ideas: this could help you to design a clear class structure, the initial author is not so bad at classes design. In this case, he pushes encapsulation to the excess but the idea is right.

Does association in UML associate objects or classes?

On Wikipedia, I'm reading that an association relationship is an instance level relationship so we are talking about the relationship between the objects of two classes.
When we actually draw a class diagram, why do we use association on the class elements or blocks rather than objects? And there are also class level relationships for which we again use class elements. Since we don't have any way to show if we are talking about objects or classes I find this confusing. For example: I've heard people saying "Associate these two classes" Doesn't that sound wrong?
Links are to Associations as Objects are to Classes.
A Class is an abstraction that describes many specific objects. Similarly, an Association is an abstraction that describes many links between objects.
So your statement
an association relationship is an instance level relationship
isn't strictly correct because it mixes the abstraction (Association Relationship) with the instances it represents.
hth.
In fact, when you associate two or more classes it is done thanks to two or more UML Properties.
These latter are the "ends" of your associations and are "instance" i.e. they are typed by classe.
So an association is created between two classes on a class diagram but between each classes and the association you have a UML property.
Hoping it sounds clear ...
When you are making a class diagram you are defining types. Suppose you have a class User and a class Account, you use an association between User and Account to say: User instances can have link(s) with Account instances at runtime.
So, you use classes and associations at type level (class diagram) to define what can be possible at runtime (instance level).
The object is actually the Class that has been created virtualy. So a class is the "static" version of an Object. So, when we speak of UML, we speak about classes and not object.
But correct me if I'm wrong!

How should I explain UML class diagram?

I have created a design using class diagram. However I was asked to give some explanation on the class diagram.
IMO, class diagram is fairly. For example, if a class is labeled as "Cat", am I going to explain, this "Cat" class represents "Cat"?
What is the best way to explain UML class diagram?
saying class Cat represents cats is one thing you can do, which is maybe not very exciting, though. More interesting to explain might be: associations, abstract classes, interfaces, inheritances, etc. is there any design pattern you are using? maybe explain them.
I hope this will help!
Suppose you have to explain this class diagram to your client in lieu your manager will. Just think how you will define all the responsibilities of each class present in that diagram. Give one-liner definition of its properties, methods, parent and child classes etc (go in bit more details when needed as well).
Define what would be the flow and how one class will link to another one.
For example:
Is your class 'cat' has any association with class Animal or interface IAnimal. You can think more of it and go better.
whatever the type of uml diagram, you should always add some explanantions in natural language.
at least explain some key aspects of the solution : this has a reference to this
this inherits from this class and do not need to override this operation.

UML High Level Class Diagram

can somebody please explains what is a high level class diagram. As far as I know class diagram shows the association between the classes but what about high level class diagram??
Ok, I knew what this means, a Class Diagram contains many details. A high-level class diagram is a simple class diagram reflecting only initial domain knowledge
What's the context? Class diagrams in themselves are pretty "high-level", in that they only show classes and methods rather than algorithms and other implementation details. It might just be an adjective. Or, you might be looking for something more like a block-level diagram which shows components of a system and how they interact.
I often use the term "high-level", or more usually, "top-level" diagram for the very highest level class diagram I make for a system. Usually this will show as many of the most important packages as will reasonably fit, along with some classes that give the best idea of what functionality the classes in that package provide. From there I can do class diagrams of each package, and so on.
Depending on the type of system and what your supervisor want to see, you may be better off creating a component diagram.

What kind of UML diagram is this?

What kind of UML diagram is this?
(source: tripod.com)
This is a class diagram, with added stereotypes
This is Class Diagram in a very abstract or initial form because all relationship are shown as Association.
Usually we start with such class diagram and then keep on refining by converting association (arrow as shown above) into more stronger relationship like generalization,composition,implementation etc.
Association is considered as weaker form of relationship between classes. So final class diagram should have fewer associations.
What is the emphasis or goal of this diagram? If it's the classes and relationships, then it's a class diagram. If it's the mapping between the classes and layers of function or responsiblity in the system, then it looks like a layer diagram. Those columns look like layers: presentation, business logic, data...
Ok now I see the problem after a good sleep :-)
It seems it is a powerpoint and not a class diagram because you can not have straight line in a class diagram. I mean you can not have 3 separators like Presentation/ objectos .......etc
This powerpoint tried to use class diagram and have added titles in order to separate 3 layers. The problem is that the class diagram is incorrect and it is not because you present it with 3 layer that it would become correct !! This is a bad understanding of what means JPA stereotypes inside a class diagram.
It looks like a Class Diagram that uses "swimlanes" on the background to facilitate some kind of MVC.
This class diagram is not correct because there is confusion between Java EE stereotypes and class names!
What are the << class module>> , << module>> stereotypes and Session, Session persistence names should be Java EE stereotypes. If it persists in the database then it is an entity! Persistence etc...can be written on attributes.
This diagram doesn't make sense!
The main advantage of scheme in this diagram is that if you use a code generator such as AndroMDA, MIA software or Blue Age, then you can then generate your database directly from the model. These tools look at stereotypes during code generation.
If you don't want to generate code from a model but prefer to let hibernate mapping do the job, then the "entity" stereotype can be written as an annotation in your java code. Then thanks to live code and model synchronization, hibernate can take the annotation and produce a mapping.
This is why stereotyping is really very important and using the wrong stereotype can be a very serious mistake!

Resources