I can't decide how to show constant class properties in Uml Diagram. Can you suggest me how to do it?
I would do it like this:
CONSTANT_NAME : constant_type = value
E. g.:
PI : double = 3.1415
Related
I want to represent the following case using UML class diagram:
a class A that has some elements of C
a class B that is a subclass of A that contain 1 element of D that is subclass of C
Something like:
Example
Basically (in my mind), the class A has a collection of C but the subclass B only allows (at maximum) one element in that collection that should be instance of D.
What is the best way of representing it?
To change (limit) a cardinality or to specialise the type of element in a subclass you have to use a "redefines" constraint.
In your case your if your attribute in class A is
anAttribute:C[*]
Then in class B you'll have
anAttribute:D[0..1] {redefines anAttribute}
Of course you can use the same on an attribute shown as association (like in your diagram), then just add {redefines anAttribute} near the end of association (and of course association ends should both be named anAttribute then).
How would I go about showing that class A inherits a vector of pointers to Class B? Would I have an inheritance arrowhead to Vector, or to Class B?
There is no such thing as "class A inherits some resource to class B". Either class B inherits from class A - in this case B specializes A (or, alternatively, A generalizes B); or class A and class B share a resource - in this case it's called aggregation.
Can someone please help me understand predicates using the following example:
sig Light{}
sig LightState { color: Light -> one Color}
sig Junction {lights: set Light}
fun redLigths(s:LightState) : set Light{ s.color.Red}
pred mostlyRed(s:LightState, j:Junction){
lone j.lights - redLigths(s)
}
I have the below questions about the above code:
1) What happens if the above predicate is true?
2) What happends if it is false?
3) Can someone show me a bit of alloy code that uses the above code and clarifies the meaning of predicates through the code.
I am just trying to understand how do we use the above predicate.
Nothing "happens" until you place a call to a predicate or a function in a command to find an example or counterexample.
First, use the right terminology, nothing 'happens' when a predicate is true; it's the more like the other way around, an instance (an allocation of atoms to sets) satisfies (or doesn't) some condition, making the predicate true (or false).
Also, your model is incomplete, because there is no sig declaration for Color (which should include an attribute called Red).
I assume you want to model a world with crossroads containing traffic lights, if so I would use the following model:
abstract sig Color {}
one sig Red,Yellow,Green extends Color {}
sig Light {
color: Color
}
sig Junction {
lights : set Light
}
// This is just for realism, make sure each light belongs to exactly one junction
fact {
Light = Junction.lights
no x,y:Junction | x!=y and some x.lights & y.lights
}
fun count[j:Junction, c:Color] : Int {
#{x:Light | x in j.lights and x.color=c}
}
pred mostly[j:Junction, c:Color] {
no cc:Color | cc!=c and count[j,cc]>=count[j,c]
}
run{
some j:Junction | mostly[j,Red]
} for 10 Light, 2 Junction, 10 int
Looking at the above, i'm using the # operator to count the number of atoms in a set, and I'm specifying a bitwidth of 10 to integers just so that I don't stumble into an overflow when using the # operator for large sets.
When you execute this, you will get an instance with at least one junction that has mostly red lights, it will be marked as $j in the visualizer.
Hope this helps.
sig Light{}
sig LightState { color: Light -> one Color}
sig Junction {lights: set Light}
fun redLigths(s:LightState) : set Light{ s.color.Red}
pred mostlyRed(s:LightState, j:Junction){
lone j.lights - redLigths(s)
}
What the predicate simply means in the example you gave is;
The difference between the set A, in this case the relation (j.lights) and another set say B, returned from the function redligths, of which the Predicate will always constraint the constraint analyser to return only red light when you run the Predicate "mostlyRed".
And note that the multiplicity "lone" you added to the predicate's body only evaluate after the difference between the set A and B (as I assumed) has been evaluated, to make sure that at most one atom of red is returned. I hope my explanation was helpful. I will welcome positive criticism. Thanks
I am using PlantUML to make simple class diagrams and the tool is awesome, but I couldn't find any way to align classes with each other except putting them into packages or using relationships like Alice -left-* Bob. What I need is something like:
#startuml
class Bob
class Alice
class Dan
**Dan aligned Alice: horizontally**
'or using a grid?
**Bob at grid (2, 3)**
#enduml
Is there a way?
UPDATES Aug.08.2019
From Rotsiser's comment, by combining changing the length of lines with together keyword, it can align elements
#startuml
class A
A ..> B
C ---> B
D ...> B
together {
class E
class F
class G
}
E ----> B
#enduml
OUTDATED
You are able to align elements by changing the number of line's character, such as '-', '.', and so on.
#startuml
class A
A ..> B
C ---> B
D ...> B
E ----> B
F ----> B
G ----> B
#enduml
Using a -[hidden] relation can do the job :
#startuml
class Bob
class Alice
class Dan
class Foo
class Bar
class Foobar
Bob -[hidden] Alice
Bar -[hidden] Foobar
#enduml
No, there's no way to do that, sorry :( The idea behind PlantUML is that you should not care too much about the layout rendering.
Actually, early versions of PlantUML use to align classes, but it was an issue: When there were many unrelated classes, diagrams tended to be very large and very thin. So a patch was added to organize classes in a square.
How many classes do you want to have in your diagram? Sure it would be possible to disable the organizing patch for e.g. 3 to 5 classes. You could post a suggestion to the forum to see what other users think about it.
Here is a solution.
The documentation:
"It is also possible to change arrow direction by adding left, right, up or down keywords inside the arrow:"
#startuml
foo -left-> dummyLeft
foo -right-> dummyRight
foo -up-> dummyUp
foo -down-> dummyDown
#enduml
To your question:
#startuml
class Bob
class Alice
class Dan
Alice -left[hidden]-> Bob
Alice -right[hidden]-> Dan
#enduml
It may also be useful:
#startuml
class Bob
class Alice
class Dan
Bob -right-|> Alice
Alice -right-> Dan
interface Friend
Dan -up..> Friend
interface Person
Friend -left-> Person
interface Object
Person -down-> Object
interface Native
Object -right-> Native
#enduml
You don't need a hidden package, use the together keyword:
together {
class A
class B
}
A cleaner approach is to put them in a hidden package, which is more logical.
#startuml
skinparam shadowing false
skinparam package<<Layout>> {
borderColor Transparent
backgroundColor Transparent
fontColor Transparent
stereotypeFontColor Transparent
}
package x <<Layout>>{
class A
class B
}
A .. D
B .. C
C .. D
A1 .. D1
B1 .. C1
C1 .. D1
#end
<< enumeration>> E1 | .RED .GREEN .BLUE |
I have the above as an enumeration class in a UML diagram. I associate it with another class say House. I now need a method on House say +getColor() which returns a color from the above enumeration.
How would I depict this in UML?
would it be like : +getColor(): E1 ?
Yes, your suggestion is right and depending on the level of detail, you could also add dependency from House to E1.