% Radiation-simulation class diagram from the TikZ-UMLD worked example. % Compile with: pdflatex tikz-umld-example.tex % Requires the tikz-umld and standalone packages. \documentclass[tikz,border=6pt]{standalone} \usepackage[T1]{fontenc} \usepackage{tikz-umld} \newcommand{\bb}[1]{\textbf{#1}} \begin{document} \begin{tikzpicture} \umlclass[x=-6,y=6]{Globe}{ - radiation: Radiation\\ }{ + simulate(x: int): Plant?\\ } \umlclass[x=-12,type=abstract]{Plant}{ \umlcon{\# name: string}{getter}\\ \umlcon{\# nutrition: int}{getter}\\ }{ \umlpvirt{+ newDay(Radiation)}\\ \umlcon{+ isAlive(): bool}{virtual,query}\\ + nutrify(n: int)\\ } \umlclass[x=-16,y=-5.4]{Puffy}{ \umlcon{+ fav: Radiation := Alpha}{readonly}\\ }{ \umloverrd{+ newDay(r: Radiation)}\\ \umlcon{+ isAlive(): bool}{query,override}\\ } \umlclass[x=-12,y=-7.8]{Deltree}{ \umlcon{+ fav: Radiation := Delta}{readonly}\\ }{ \umloverrd{+ newDay(r: Radiation)}\\ } \umlclass[x=-7,y=-10]{Parax}{ \umlcon{+ fav: Radiation := None}{readonly}\\ }{ \umloverrd{+ newDay(r: Radiation)}\\ } \umlclass[x=12,type=abstract]{Radiation}{ \umlcon{\# requested: int := 0}{getter} }{ + request(n: int)\\ \umlpvirt{+ radiate(Puffy)}\\ \umlpvirt{+ radiate(Deltree)}\\ \umlpvirt{+ radiate(Parax)}\\ } \umlclass[x=4,y=-6,type=singleton]{Alpha}{ }{ \umloverrd{+ radiate(p: Puffy)}\\ \umloverrd{+ radiate(p: Deltree)}\\ \umloverrd{+ radiate(p: Parax)}\\ } \umlclass[x=12,y=-6,type=singleton]{Delta}{ }{ \umloverrd{+ radiate(p: Puffy)}\\ \umloverrd{+ radiate(p: Deltree)}\\ \umloverrd{+ radiate(p: Parax)}\\ } \umlclass[x=20,y=-6,type=singleton]{None}{ }{ \umloverrd{+ radiate(p: Puffy)}\\ \umloverrd{+ radiate(p: Deltree)}\\ \umloverrd{+ radiate(p: Parax)}\\ } \umlVHaggreg[anchor1=-110,mult1=1,mult2=*,arg2=-plants,pos2=1.75]{Globe}{Plant} \umlVHcompos[anchor1=-70,mult2=*,arg2=-rads,pos2=1.95]{Globe}{Radiation} \umldep[anchors=-15 and -165]{Plant}{Radiation} \umlVHVinherit{Deltree}{Plant} \umlVHVinherit[arm1=2cm]{Puffy}{Plant} \umlVHVinherit{Parax}{Plant} \umlVHVinherit{Alpha}{Radiation} \umlVHVinherit{Delta}{Radiation} \umlVHVinherit{None}{Radiation} \umlnote[x=3,y=4.6,px=2.1,py=-0.6,width=29em]{Globe}{ radiation := None;\\ \bb{for} c \bb{in} $[1..x]$ \bb{do}\\ \, \bb{foreach} Plant p \bb{in} plants \bb{do}\\ \, \, \bb{if} p.isAlive() \bb{then} p.newDay(radiation) \bb{endif}\\ \, \bb{end foreach}\\ \, \textit{Radiation} max := None; \textit{Radiation} max2 := None;\\ \, \bb{foreach} Radiation r \bb{in} rads \bb{do}\\ \, \, \bb{if} r.Instance().getRequested()$>$max.Instance().getRequested()\\ \, \, \, \bb{then} max2 := max; max := r;\\ \, \, \bb{elif} r.Instance().getRequested()$>$max2.Instance().getRequested()\\ \, \, \, \bb{then} max2 := r;\\ \, \, \bb{endif}\\ \, \bb{end foreach}\\ \, \bb{if} max.Instance().getRequested()$>$max2.Instance().getRequested()$+3$\\ \, \, \bb{then} radiation := max;\\ \, \bb{else} radiation := None;\\ \, \bb{endif}\\ \bb{end for}\\ \bb{return} plants.\bb{Where}(p=>p.isAlive()).\bb{MaxBy}(p=>p.getNutrition());\\ } \umlnote[x=-17,y=1.5,px=-2.5,py=-1,width=10em,anchor1=-30]{Plant}{ \bb{return} 0