Skip to main content

ClassDiagram

The following classes can be useful when creating class diagrams:

  • siren
  • classDiagram
  • classRltsType
  • classCardinality
  • classDirection
  • classMemberVisibility / cmv
  • classMemberClassifier / cmc
  • classConfig

Animals

let duck,animal,zebra,fish = "Duck","Animal","Zebra","Fish"
siren.classDiagram [
classDiagram.note "From Duck till Zebra"
classDiagram.relationshipInheritance(duck, animal)
classDiagram.note(@"can fly\ncan swim\ncan dive\ncan help in debugging", duck)
classDiagram.relationshipInheritance(fish, animal)
classDiagram.relationshipInheritance(zebra, animal)
classDiagram.idAttr(animal,"age", "int", classMemberVisibility.Public)
classDiagram.idAttr(animal, "gender", "String", classMemberVisibility.Public)
classDiagram.idFunction(animal, "isMammal", classMemberVisibility = classMemberVisibility.Public)
classDiagram.idFunction(animal, "mate", classMemberVisibility = classMemberVisibility.Public)
classDiagram.``class``(duck,members=[
classDiagram.classAttr("beakColor","String", classMemberVisibility.Public)
classDiagram.classFunction("swim", classMemberVisibility = classMemberVisibility.Public)
classDiagram.classFunction("quack", classMemberVisibility = classMemberVisibility.Public)
])
classDiagram.``class``(fish,members=[
classDiagram.classAttr("sizeInFeet","int", classMemberVisibility.Private)
classDiagram.classFunction("canEat", classMemberVisibility = classMemberVisibility.Private)
])
classDiagram.``class``(zebra,members=[
classDiagram.classAttr("is_wild","bool", classMemberVisibility.Public)
classDiagram.classFunction("run", classMemberVisibility = classMemberVisibility.Public)
])
classDiagram.``namespace``("Mammals", [
classDiagram.classId(zebra)
])
]
|> siren.write

Class

let bankacc = "BankAccount"
siren.classDiagram [
classDiagram.classId(bankacc)
classDiagram.idAttr(bankacc,"owner", "String", classMemberVisibility.Public)
classDiagram.idAttr(bankacc,"balance", "Bigdecimal", classMemberVisibility.Public)
classDiagram.idFunction(bankacc,"deposit", "amount", classMemberVisibility = classMemberVisibility.Public)
classDiagram.idFunction(bankacc,"withdrawal", "amount", classMemberVisibility = classMemberVisibility.Public)
]
|> siren.withTitle ("Bank example")
|> siren.write

Generic Types

let square = "Square"
siren.classDiagram [
classDiagram.classId(square, generic="Shape", members=[
classDiagram.classAttr("id", "int")
classDiagram.classAttr("position", "List<int>")
classDiagram.classFunction("setPoints", "List<int> points")
classDiagram.classFunction("getPoints", returnType = "List<int>")
])
classDiagram.idAttr(square, "messages", "List<string>", classMemberVisibility.Private)
classDiagram.idFunction(square, "setMessages", "List<string> messages", classMemberVisibility = classMemberVisibility.Public)
classDiagram.idFunction(square, "getMessages", returnType = "List<string>", classMemberVisibility = classMemberVisibility.Public)
classDiagram.idFunction(square, "getDistanceMatrix", returnType = "List<List<int>>", classMemberVisibility = classMemberVisibility.Public)
]
|> siren.write

Annotations

siren.classDiagram [
classDiagram.``class``("Shape", members=[
classDiagram.Interface()
classDiagram.classAttr("noOfVertices")
classDiagram.classFunction("draw")
])
classDiagram.``class``("Color", members=[
classDiagram.enumeration()
classDiagram.classAttr("RED")
classDiagram.classAttr("BLUE")
classDiagram.classAttr("GREEN")
classDiagram.classAttr("WHITE")
classDiagram.classAttr("BLACK")
])
]
|> siren.write

Diagram direction

let student, idCard, bike = "Student", "IdCard", "Bike"
siren.classDiagram [
classDiagram.directionRL
classDiagram.``class``(student, members=[
classDiagram.raw("-idCard : IdCard")
])
classDiagram.``class``(idCard, members=[
classDiagram.raw("-id : int")
classDiagram.raw("-name : string")
])
classDiagram.``class``(bike, members=[
classDiagram.raw("-id : int")
classDiagram.raw("-name : string")
])
classDiagram.relationshipAggregation (student, idCard, "carries", classCardinality.one, classCardinality.one)
classDiagram.relationshipAggregation (student, bike, "rides", classCardinality.one, classCardinality.one)
]
|> siren.write