Two classes with a same name in PlantUML class diagram - class-diagram

Dear community members and PlantUml practitioners,
I would like to have two classes with the same name such as:
Test << stereotype >>
Test
and I would like to make relation between those two classes.
Is it possible to make alias for classes in class diagram so I can make distinction between the classes thus those will be represented as two different elements.
Any idea?

With plantuml you can alias a display name using "as." For class diagrams it looks Like this:
#startuml
class "Test" as t1
class "Test" as t2
t1 -> t2
#enduml

Related

how can vb.net make inherit class with selected variable from base calss

I need to make an inherited class from a base class with a selected variable.
for example,
if the base class have 3 variable name, age, marks
but inherit class must have name and marks only
how can we do it
When designing object-oriented code, subclasses should be the specializations. The situation you describe makes the base class the specialization because it has more specific requirements than the subclass.
There is a principle called the "Liskov Substitution Principle" that says all subclasses should work where the base class works - and this wouldn't be the case as calling subclass.age would fail.
Instead, the base class should have the two common properties, and there should be a subclass that represents the extended class that represents the situation where an age would be used.
Score
Name
Marks
AgedScore extends Score
Age
The names are examples here, ideally you'd name them after what they relate to in the business domain.

How do you show encapsulation in UML class diagram?

My question is pretty straightforward. How do I represent or show encapsulation when modelling a UML class diagram? Inheritance is modelled using the arrows and an abstract class is shown by having the class name in italics or between the following arrows as shown, << Animals >> but what do you do for encapsulation?
Each feature of a class can have a visibility. Private features make it possible to encapsulate the state of the instance. The notation for a private feature is a - sign in front of its name (+ for public, # for protected and ~ for package visibility).
PS: An abstract class is not shown with "arrows". Instead it is shown with the word {abstract} in curly brackets (or as you correctly state by writing the name in italics).
PPS: "Arrows" (<<...>>) are not UML notation. You probably mean guillemets: «...». They are used to annotate language elements, that don't have a distinct notation, like DataTypes. In this case the keyword «dataType» is shown above the name. They could also be the notation for a property of a language element. For example an Activity with isSingleExecution=true will show the keyword «singleExecution». Why this case is not expressed with curly brackets, as in the case of isAbstract=true is shrouded in mystery. Finally they are used for user defined language elements (=stereotypes). Please note, that such elements are one level above the model elements, i.e. on the language level (also called meta level). Therefore, they don't express anything on the level of the modeled system. A stereotype «Animals» defines a new language element, but not an animal.

Peewee Meta class inherence

I am struggling with the following:
from my_db_definition import db
from peewee import *
class A(Model):
class Meta:
database=db
table_name = 'random'
class B(A):
pass
when running
print(A._meta.table_name)
print(B._meta.table_name)
random
b
My question is now, why is the table name changed in this case, and can this be prevented? I am completely confused
http://docs.peewee-orm.com/en/latest/peewee/models.html#model-options-and-table-metadata
The docs list which options are inherited and which are not.
Only certain attributes are passed to the subclass via the inner "Meta" class. It's purpose is 1) namespacing, and 2) provide conventions around DRY code.
table name is not inherited because presumably you only want one class-per-table, whereas database is inherited because it makes sense to only declare that once.

UML Design class diagram: Class with another class as attribute?

I'm having a pretty hard time trying to figure out how to model a certain scenario as a UML design class diagram.
Suppose I have the following situation:
I have a class named CPoint that has two attributes: x and y (coordinates in a R2 plane). Additionally, I have a class named CLine that should have two CPoint as attributes.
This is pretty straight forward to code (I'll use C++ in my example):
class CPoint{
float x;
float y;
//Constructor, gets and sets here
}
And for CLine:
class CLine{
CPoint p1;
CPoint p2;
//Constructor, gets and sets here
}
Now my question is: How do I model such a thing in UML?
I thought of something similar to this:
But then I was told that this is violating the principles of object oriented modeling, so then I did this:
But it does not convince me at all. Additionally, I was reading about design patterns and came to this UML design while reading about singletons:
Which makes me think my initial approach was just right. Additionally, I'm able to see that my first approach is just alright if I think about it as a C++ program. In Java, however, I'd still have to create the object by doing new CPoint(0, 0) in the CLine's constructor. I'm really confused about this.
So, how do I model this situation? Am I perhaps being too concrete when I attempt to model the situation?
Thanks in advance! This isn't letting me sleep at night
In UML an association or an attribute (property) are more or less the same thing, so they are both correct.
In most UML tools however they are different things.
There is not really a rule here, but there are best practices.
My UML Best Practice: Attribute or Association says:
Use Associations for Classes and Attributes for DataTypes
If your CLine has exactly two ends represented by point, than you can define it in UML as class CLine with attributes (just like your CLine on the first example is OK but without association "has") or you can design it as CLine class with two association to CPoint. Multiplicity at CPoint will be 1 with role p1 for the first one and p2 for the second one at the CPoint side.
There is not one best solution. It depends on the context and what you want to model. I agree with Vladimir that you would have two relations with roles p1 and p2. The members x and y should be private I guess (-x, -y) and not public (+x, +y). Furthermore you could model the relation as aggregate or composite (open or closed diamond symbol) but if a single point can be the endpoint of two lines then that is not appropriate. Again, this depends on what you want to model. If construct a new point in the line constructor as stated in the question, then you probably want to use a composition relation as these points do not exist without the line.
(Btw, in the code the coordinates are float and in the diagram ints).

ArrayList or Aggregation with specified multiplicity

I am just starting with UML (StarUML 5) so please excuse this really basic question.
Let's say a Person has multiple Characteristics, each of which has a Name and a Value. (This is just to keep things simple.) Suppose I create the Characteristic class accordingly.
I want to generate Java class Person with a property something like ArrayList(Characteristic).
Should I add an attribute to the Person class like ArrayList(Characteristic), or should I just use an Aggregation relationship between Person and Characteristic and specify the multiplicity as 0..* ?
On the first (ArrayList) approach I don't even model the multiplicity. On the second (Aggregation) approach the Java code creates a property in Person of type Characteristic but not a "List-like" property, i.e. it ignores the multiplicity in the diagram.
Thank you.
I agree with Dave, this is a composition, a kind of UML association. Setting the composition as Ordered and not unique allows to generate the Java attribute as a List. It means you have a composition at the design level and a List at the implementation level. That's the code generator - or you if you don't use code generation - which correctly translates the UML diagram.
Here's what I would design in your case and the Java code I generated (feel free to fork):
public class Person
{
/**
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* #generated
* #ordered
*/
public List<Characteristic> characteristic;
/**
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* #generated
*/
public Person(){
super();
}
}
Notice you can import StarUML projects in GenMyModel if you'd like to quickly design generate online.
This sounds like a composition relationship to me. In my opinion you're better off with the second approach using Aggregation/Composition. Here is an interesting read on one take on Attribute vs Association. Regarding the failure of StarUML to implement the relationship correctly, you might be better off just implementing the List yourself.