What is the relationship between class and data types in class diagram? - struct

I'm working on a class diagram and I'm using the Enterprise Architect.
Suppose that we have a class.
I should use a struct data type that is a global data type and all classes use it.
Also I should define another struct data type that it is supposed to be used inside the class.
I have this scenario for an enumeration.
The question that I have is that what kind of relationship(composition, aggregation, dependency, etc.) should I use in the class diagram for private/public struct and enumeration data types?

Related

Do you need to register all implementations of an interface with Kryo?

When using Kryo, it's generally recommended that you register the classes you intend to serialize so the class name doesn't need to be included in the serialized data.
But in a class hierarchy, the actual implementation class may not be obvious. For example, if I have a Spark dataset that contains Vector objects, those objects' concrete class may be either DenseVector or SparseVector.
When I register the classes with Kryo, should I:
Register the class according to the dataset's declared type (Vector)
Register the concrete classes (DenseVector and SparseVector)
All of the above, just in case?
Bonus question: if the Vector appears as a field in a tuple or case class, would you also need to register the product (Tuple2[Vector, Int] for example)?
Answer to main question
The answer is... no 2 :) In other words:
you need to register the concrete classes only, and
you need to register every single concrete class that you may encounter1.
Unfortunately, I have no documentation reference to back this up right now (I know it from experience).
1 There is a special case, though, when you can register only an abstract class for the purposes of serialization/deserialization (not for Kryo.copy() though). This case is when:
your serialization is the same for all subclasses, and
during deserialization, you can decide which subclass to return based on the data.
Look at the ImmutableListSerializer by Martin Grotzke. In the registerSerializers method, he registers only ImmutableList class for the purposes of serialization/deserialization because:
serialization is the same, and
during deserialization, ImmutableList.copyOf() takes care of returning the proper subclass.
Answer to bonus question
If the Vector appears in a tuple or case class, you need to register the appropriate class (e.g. Tuple2).
Note that generic types do not matter here as long as you serialize using Kryo.writeClassAndObject (e.g. ImmutableListSerializer extends Serializer<ImmutableList<Object>>).

Is calling a method considered a relationship on a class diagram?

I'd like to know if calling a method from a different class is considered a relationship on a class diagram.
Regards.
Not always. Some types of relationships (e.g. a uses b, a notifies b, etc) can be implemented or supported by calling of an object's method thoough.
It depends on how closely the class diagram represents relationships. That is a design choice.

UML Query for class diagram relationship

A few query and opinions to seek on the best type of relationship and representation to be used in a class diagram for modelling with uml
1) Third party library used by my class
-- I have modeled them as packages
2) Wrapper Class to wrap around modified code
-- I have modeled this class as an interface
3) My wrapper class actually use non-class member function that is written in another namespace
-- This puzzled me. How should I modeled them?
4) For classes in my own created library(dll), how do i differentiate the class that is exported and those that is not
Thanks
1) That's fine. However, it depends on the layer. I could think of a component to represent a library.
2) Not necessary. A wrapper inherits from a class. So use a generalization.
3) You can not really do that. You might use an artifact and a relation (association) to it.
4) I would use a component with interfaces (lollipops) to show the exported ones. The others are kept inside.
For all answers: YMMV

Is there a way to specify a relationship whereby a class generates the code for another class? UML

I am writing a system which generates code for a number of classes and I need to document it with a UML diagram. The classes will follow the same structure but they will have names set by the user. Is there a way to specify that CCodeGenerator generates the code for these classes?
Also, I currently have a relationship between my CDataDefinition class (which defines what should be included in each of the generated classes) and the CCodeGenerator, is there a way to denote that the multiplicity of the relationship between the generated classes and the generator is exactly equal to the number of CDataDefinition instances?
These classes will be used in another system which will also need UML class diagrams made for it. Is there a way to show that a class in this project (CEditior) uses them?
Example of operation:
I have 3 CDataDefinition objects which define classes X, Y, and Z. My CCodeGenerator instance will create 3 classes (C# code in .cs files) from these.
CEditor in a separate solution will then interface with these 3 classes.
If you read some of the introductory information on MOF, you will see that in the UML family an instance of a metaclass in one layer is a classifier in the next.
In your case, a class in the code generator describing the class in its output will be a metaclass (CDataGenerator), and the classes in the output represented by instances of the metaclass.
There is no way in plain UML for associations other than 'X is of type Y' to cross between the layers.
You may be able to model such a relationship using MOV QVT (query, view, transform - i.e. a language for mapping one model to another), but I don't know current state of tool support for that, and if you had a QVT tool you probably wouldn't need to be writing a code generator.
You need to build a template class (CDataDefinition) that will represent the structure of a class that can be created by CCodeGeneratorWhen you're creating actual class you do the binding so all you have to do is show that CCodeGenerator has an operation (let's say) classGenerator(name:String) and then you can show that this method creates a class as a proper binding on CDataDefinition.

UML class diagram relation type question

I have a data class with the following methods:
ExecuteUDIQuery(string query)
ExecuteSelectQuery(string query)
ExecuteSP(string anme, string[,] params)
I have a lot classes which use the data class. Now i want to create a class diagram, but i don't know what kind of relation the classes have with the data class. Is it a composite? Is it 1:1 or .. ?
An example of a class which use the data class is the Staff class. This class has a method Load(), which will load a staff object with the Id of the staff member. This method contains a query which is passed to the ExecuteSelectQuery(string query) method of the Data class.
EDIT:
The data class isn't static. However, i have my doubts. I actually don't know what to. The point is, the only thing it does is executing queries and returning the results.
I would suggest its a usage dependency relationship.
See here for a brief description.
I would query the naming of your classes. a class name should normally be a singular noun. Examples;
Window
Person
Transaction
Data is a plural, and in any case I think it should be Database.
Similarly for Staff - once again a plural, I think it should be MemberOfStaff. Unless of course it is a list of members of staff, in which case I would call it something like Department, Project or Division - whatever your problem domain indicates.
You will find that coming up with good names for classes is suprising ly difficult, but it is well worth the effort.
The difference between aggregations, composites and 1 on 1 relations are a bit vague and somewhat arbitrary.
I use the aggregation (open diamond) if one class owns the other class (is responsible for the lifecycle.
I use 1 on 1 relationships in all other cases.
Is the class instantiated by the classes that use it or are the methods static?
If they are static I would represent this as an unqualified dependency (dotted arrow pointing from the classes that is using the data class to the data class)
If the classes that are using the data class create their own private instance of that class this would be a 1:1 composition (assuming that the data class instance's lifcycle is tied to the object that is using it)
I cannot refrain from commenting your overall design, I would try to move the Load method out of the Staff class, so that this class is not dependent on the Data class directly.
Within the scope of your existing design I would suggest the following:
If the staff class contains an instance variable of the data class, then it is an association. If the data class is instantiated just to retrieve the instance, it is just a dependency of a given type, like #toolkit says.
Not enough data.
Give us some class outlines or something. From what I can see, I wouldn't have actually called this a data class (it looks more like a data accessor) which sounds like it might be a singleton (many:1, aggregation or association), or if instanced will be a 1:1 component.
Now i want to create a class diagram, but i don't know what kind of relation the classes have with the data class.
Nor do we - you've only described the Data class, and not said how Staff gets the Data it uses.
If Staff holds on to one or more instances of the data class, then there is either an association between Staff and Data, or Staff has an attribute of type Data (if Data has value semantics).
If the Data instances are referenced by multiple Staff instances, and their lifecycles are dependent on being referenced by Staff instances then this may be shown as an aggregation relation. If the Data instances are not shared between Staff instances and their lifecycles are dependent on being referenced, then this may be shown as an composition relation.
If X doesn't keep hold of the Data instances it uses, then a usage relationship is appropriate.
Dependency and Usage are the two weakest kind of "connectors". You might consider stereotypes, keywords to refine the relationship. You might find that instantiate,call,create,send stereotypes work. Without more information though the correct answer seems to be usage.

Resources