-
Notifications
You must be signed in to change notification settings - Fork 0
/
class.tex
758 lines (592 loc) · 18.2 KB
/
class.tex
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
% ========================================================================
% PlantUML : a free UML diagram generator
% ========================================================================
%
% (C) Copyright 2009, Arnaud Roques
%
% Project Info: http://plantuml.sourceforge.net
%
% This file is part of PlantUML.
%
% PlantUML is free software; you can redistribute it and/or modify it
% under the terms of the GNU General Public License as published by
% the Free Software Foundation, either version 3 of the License, or
% (at your option) any later version.
%
% PlantUML distributed in the hope that it will be useful, but
% WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
% or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
% License for more details.
%
% You should have received a copy of the GNU General Public
% License along with this library; if not, write to the Free Software
% Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
% USA.
%
% [Java is a trademark or registered trademark of Sun Microsystems, Inc.
% in the United States and other countries.]
%
% Original Author: Arnaud Roques
%
\section{Class Diagram}
% ========================================================================
\subsection{Relations between classes}
\begin{description}
\item Relations between classes are defined using the following symbols :
\begin{tabular}{|l|l|l|} \hline
Extension & \texttt{<|--} &
\includegraphics[width=6mm]{img/extends01.png}
\\ \hline
Composition & \texttt{*--} &
\includegraphics[width=7mm]{img/sym03.png}
\\ \hline
Agregation & \texttt{o--} &
\includegraphics[width=7mm]{img/sym01.png}
\\ \hline
\end{tabular}
\item It is possible to replace "\texttt{--}" by "\texttt{..}" to have a dotted
line.
\item Knowing thoses rules, it is possible to draw the following drawings:
\end{description}
\begin{lstlisting}
@startuml
Class01 <|-- Class02
Class03 *-- Class04
Class05 o-- Class06
Class07 .. Class08
Class09 -- Class10
Class11 <|.. Class12
Class13 --> Class14
Class15 ..> Class16
Class17 ..|> Class18
Class19 <--* Class20
@enduml
\end{lstlisting}
\begin{center}
\includegraphics[width=170mm]{class.png}
\end{center}
% ========================================================================
\newpage \subsection{Label on relations}
\begin{description}
\item It is possible a add a label on the relation, using "\texttt{:}", followed
by the text of the label.
\item For cardinality, you can use double-quotes \texttt{""} on each side
of the relation.
\end{description}
\begin{lstlisting}
@startuml
Class01 "1" *-- "many" Class02 : contains
Class03 o-- Class04 : agregation
Class05 --> "1" Class06
@enduml
\end{lstlisting}
\begin{center}
\includegraphics[width=80mm]{class_001.png}
\end{center}
% ========================================================================
\newpage \subsection{Adding methods}
\begin{description}
\item To declare fields and methods, you can use the symbol "\texttt{:}"
followed by the field's or method's name.
\item The system checks for parenthesis to choose between methods and fields.
\end{description}
\begin{lstlisting}
@startuml
Object <|-- ArrayList
Object : equals()
ArrayList : Object[] elementData
ArrayList : size()
@enduml
\end{lstlisting}
\begin{center}
\includegraphics[width=25mm]{class_002.png}
\end{center}
\begin{description}
\item It is also possible to group between brackets \texttt{\{\}}
all fields and methods.
\end{description}
\begin{lstlisting}
@startuml
class Dummy {
String data
void methods()
}
@enduml
\end{lstlisting}
\begin{center}
\includegraphics[width=25mm]{class_003.png}
\end{center}
% ========================================================================
\newpage \subsection{Defining visibility}
\begin{description}
\item When you define methods or fields, you can use characters to define the
visibility of the corresponding item:
\end{description}
\begin{tabular}{|c|c|c|l|} \hline
\texttt{-} &
\includegraphics[width=2mm]{img/PRIVATE_FIELD.png} &
\includegraphics[width=2mm]{img/PRIVATE_METHOD.png} &
\texttt{private}
\\ \hline
\texttt{\#} &
\includegraphics[width=2mm]{img/PROTECTED_FIELD.png} &
\includegraphics[width=2mm]{img/PROTECTED_METHOD.png} &
\texttt{protected}
\\ \hline
\texttt{\~} &
\includegraphics[width=2mm]{img/PACKAGE_PRIVATE_FIELD.png} &
\includegraphics[width=2mm]{img/PACKAGE_PRIVATE_METHOD.png} &
\texttt{package private}
\\ \hline
\texttt{+} &
\includegraphics[width=2mm]{img/PUBLIC_FIELD.png} &
\includegraphics[width=2mm]{img/PUBLIC_METHOD.png} &
\texttt{public}
\\ \hline
\end{tabular}
\vskip 10mm
\begin{lstlisting}
@startuml
class Dummy {
-field1
#field2
~method1()
+method2()
}
@enduml
\end{lstlisting}
\begin{center}
\includegraphics[width=20mm]{class_004.png}
\end{center}
\vskip 10mm
\begin{description}
\item You can turn off this feature using the
\texttt{skinparam classAttributeIconSize 0} command :
\end{description}
\begin{lstlisting}
@startuml
skinparam classAttributeIconSize 0
class Dummy {
-field1
#field2
~method1()
+method2()
}
@enduml
\end{lstlisting}
\begin{center}
\includegraphics[width=20mm]{class_005.png}
\end{center}
% ========================================================================
\newpage \subsection{Notes and stereotypes}
\begin{description}
\item Stereotypes are defined with the \texttt{class} keyword, "\texttt{<<}" and
"\texttt{>>}".
\item You can alse define notes using \texttt{note left of},
\texttt{note right of}, \texttt{note top of}, \texttt{note bottom of} keywords.
\item A note can be also define alone with the \texttt{note} keywords, then linked to
other objects using the "\texttt{..}" symbol.
\end{description}
\begin{lstlisting}
@startuml
class Object << general >>
Object <|--- ArrayList
note top of Object : In java, every class\nextends this one.
note "This is a floating note" as N1
note "This note is connected\nto several objects." as N2
Object .. N2
N2 .. ArrayList
@enduml
\end{lstlisting}
\begin{center}
\includegraphics[width=70mm]{class_006.png}
\end{center}
% ========================================================================
\newpage \subsection{More on notes}
It is also possible to use few html tags like :
\begin{itemize}
\item \texttt{$<$b$>$}
\item \texttt{$<$u$>$}
\item \texttt{$<$i$>$}
\item \texttt{$<$s$>$}, \texttt{$<$del$>$}, \texttt{$<$strike$>$}
\item \texttt{$<$font color="\#AAAAAA"$>$} or \texttt{$<$font
color="colorName"$>$}
\item \texttt{$<$color:\#AAAAAA$>$} or \texttt{$<$color:colorName$>$}
\item \texttt{$<$size:nn$>$} to change font size
\item \texttt{$<$img src="file"$>$} or \texttt{$<$img:file$>$} : the file
must be accessible by the filesystem
\end{itemize}
You can also have a note on several lines.
\begin{lstlisting}
@startuml
note top of Object
In java, every <u>class</u>
<b>extends</b>
<i>this</i> one.
end note
note as N1
This <size:10>note</size> is <u>also</u>
<b><color:royalBlue>on several</color>
<s>words</s> lines
And this is hosted by <img:sourceforge.jpg>
end note
@enduml
\end{lstlisting}
\begin{center}
\includegraphics[width=90mm]{class_007.png}
\end{center}
% ========================================================================
\newpage \subsection{Abstract class and interface}
You can declare a class as abstract using "\texttt{abstract}" or
"\texttt{abstract class}" keywords. The class will be printed in italic.
You can use the \texttt{interface} and \texttt{enum} keywords too.
\begin{lstlisting}
@startuml
abstract class AbstractList
abstract AbstractCollection
interface List
interface Collection
List <|-- AbstractList
Collection <|-- AbstractCollection
Collection <|- List
AbstractCollection <|- AbstractList
AbstractList <|-- ArrayList
ArrayList : Object[] elementData
ArrayList : size()
enum TimeUnit
TimeUnit : DAYS
TimeUnit : HOURS
TimeUnit : MINUTES
@enduml
\end{lstlisting}
\begin{center}
\includegraphics[width=80mm]{class_008.png}
\end{center}
% ========================================================================
\newpage \subsection{Using non-letters}
If you want to use non-letters in the class (or enum...) display, you can either :
\begin{itemize}
\item Use the as keyword in the class definition
\item Put quotes \texttt{""} around the class name
\end{itemize}
\begin{lstlisting}
@startuml
class "This is my class" as class1
class class2 as "It works this way too"
class2 *-- "foo/dummy" : use
@enduml
\end{lstlisting}
\begin{center}
\includegraphics[width=80mm]{class_009.png}
\end{center}
% ========================================================================
\newpage \subsection{Hide attributes, methods...}
\begin{description}
\item You can parameterize the display of classes using the
\texttt{hide}/\texttt{show} command.
\item The basic command is: \texttt{hide empty members}. This command will hide
attributes or methods if they are empty.
\item Instead of \texttt{empty members}, you can use:
\end{description}
\begin{itemize}
\item \texttt{empty fields} or \texttt{empty attributes} for empty fields,
\item \texttt{empty methods} for empty methods,
\item \texttt{fields} or \texttt{attributes} which will hide fields, even if
they are described,
\item \texttt{methods} wich will hide methods, even if they are described,
\item \texttt{members} wich will hide fields and methods, even if they are
described,
\item \texttt{circle} for the circled character in front of class name,
\item \texttt{stereotype} for the stereotype.
\end{itemize}
You can also provide, just after the \texttt{hide} or \texttt{show} keyword:
\begin{itemize}
\item \texttt{class} for all classes,
\item \texttt{interface} for all interfaces,
\item \texttt{enum} for all enums,
\item \texttt{<<foo1>>} for classes which are stereotyped with
\textit{foo1},
\item an existing class name.
\end{itemize}
You can use several \texttt{show}/\texttt{hide} commands to define rules and
exceptions.
\begin{lstlisting}
@startuml
class Dummy1 {
+myMethods()
}
class Dummy2 {
+hiddenMethod()
}
class Dummy3 <<Serializable>> {
String name
}
hide members
hide <<Serializable>> circle
show Dummy1 method
show <<Serializable>> fields
@enduml
\end{lstlisting}
\begin{center}
\includegraphics[width=90mm]{class_010.png}
\end{center}
% ========================================================================
\newpage \subsection{Specific Spot}
Usually, a spotted character (C, I, E or A) is used for classes, interface, enum and abstract classes.
But you can define your own spot for a class when you define the stereotype, adding a single character
and a color, like in this example:
\begin{lstlisting}
@startuml
class System << (S,#FF7700) Singleton >>
class Date << (D,orchid) >>
@enduml
\end{lstlisting}
\begin{center}
\includegraphics[width=60mm]{class_011.png}
\end{center}
% ========================================================================
\newpage \subsection{Packages}
You can define a package using the \texttt{package} keyword, and optionally
declare a background color for your package (Using a html color code or name).
When you declare classes, they are automatically put in the last used package,
and you can close the package definition using the \texttt{end package} keyword.
You can also use brackets \{ \}.
Note that package definitions can be nested.
\begin{lstlisting}
@startuml
package "Classic Collections" #DDDDDD {
Object <|-- ArrayList
}
package net.sourceforge.plantuml #Snow
Object <|-- Demo1
Demo1 *- Demo2
end package
@enduml
\end{lstlisting}
\begin{center}
\includegraphics[width=80mm]{class_012.png}
\end{center}
You can also define links between packages, like in the following example:
\begin{lstlisting}
@startuml
package foo1.foo2
end package
package foo1.foo2.foo3 {
class Object
}
foo1.foo2 +-- foo1.foo2.foo3
@enduml
\end{lstlisting}
\begin{center}
\includegraphics[width=50mm]{class_013.png}
\end{center}
% ========================================================================
\newpage \subsection{Namespaces}
In packages, the name of a class is the unique identifier of this class.
It means that you cannot have two classes with the very same name in different packages.
In that case, you should use namespaces instead of packages.
You can refer to classes from other namespaces by fully qualify them.
Classes from the default namespace are qualified with a starting dot.
Note that you don't have to explicitly create namespace : a fully qualified class
is automatically put in the right namespace.
\begin{lstlisting}
@startuml
class BaseClass
namespace net.dummy #DDDDDD
.BaseClass <|-- Person
Meeting o-- Person
.BaseClass <|- Meeting
end namespace
namespace net.foo {
net.dummy.Person <|- Person
.BaseClass <|-- Person
net.dummy.Meeting o-- Person
}
BaseClass <|-- net.unused.Person
@enduml
\end{lstlisting}
\begin{center}
\includegraphics[width=85mm]{class_014.png}
\end{center}
% ========================================================================
\newpage \subsection{Changing arrows direction}
By default, links between classes have two dashes \texttt{--} and are verticaly
oriented. It is possible to use horizontal link by putting a single dash (or dot) like this:
\begin{lstlisting}
@startuml
Room o- Studient
Room *-- Chair
@enduml
\end{lstlisting}
\begin{center}
\includegraphics[width=40mm]{class_015.png}
\end{center}
You can also change directions by reversing the link:
\begin{lstlisting}
@startuml
Studient -o Room
Chair --* Room
@enduml
\end{lstlisting}
\begin{center}
\includegraphics[width=40mm]{class_016.png}
\end{center}
It is also possible to change arrow direction by adding \texttt{left},
\texttt{right}, \texttt{up} or \texttt{down} keywords inside the arrow:
\begin{lstlisting}
@startuml
foo -left-> dummyLeft
foo -right-> dummyRight
foo -up-> dummyUp
foo -down-> dummyDown
@enduml
\end{lstlisting}
\begin{center}
\includegraphics[width=70mm]{class_017.png}
\end{center}
You can shorten the arrow by using only the first character of the direction
(for example, \texttt{-d-} instead of \texttt{-down-}) or the two first
characters (\texttt{-do-})
Please note that you should not abuse this functionnality : \textit{GraphViz}
gives usually good results without tweaking.
% ========================================================================
\subsection{Lollipop interface}
You can also define lollipops interface on classes, using the following syntax:
\begin{itemize}
\item \texttt{bar ()- foo},
\item \texttt{bar ()-- foo},
\item \texttt{foo -() bar}
\end{itemize}
\begin{lstlisting}
@startuml
class foo
bar ()- foo
@enduml
\end{lstlisting}
\begin{center}
\includegraphics[width=40mm]{class_018.png}
\end{center}
% ========================================================================
\subsection{Title the diagram}
The title \texttt{keywords} is used to put a title.
You can use title and end title keywords for a longer title, as in sequence diagrams.
\begin{lstlisting}
@startuml
title Simple <b>example</b>\nof title
Object <|-- ArrayList
@enduml
\end{lstlisting}
\begin{center}
\includegraphics[width=25mm]{class_019.png}
\end{center}
% ========================================================================
\newpage \subsection{Association classes}
You can define \textit{association class} after that a relation has been defined
between two classes, like in this example:
\begin{lstlisting}
@startuml
Student : Name
Student "0..*" - "1..*" Course
(Student, Course) .. Enrollment
Enrollment : drop()
Enrollment : cancel()
@enduml
\end{lstlisting}
\begin{center}
\includegraphics[width=50mm]{class_020.png}
\end{center}
You can define it in another direction:
\begin{lstlisting}
@startuml
Student : Name
Student "0..*" -- "1..*" Course
(Student, Course) . Enrollment
Enrollment : drop()
Enrollment : cancel()
@enduml
\end{lstlisting}
\begin{center}
\includegraphics[width=35mm]{class_021.png}
\end{center}
% ========================================================================
\newpage \subsection{Skinparam}
You can use the \texttt{skinparam} command to change colors and fonts for the
drawing. You can use this command :
\begin{itemize}
\item In the diagram definition, like any other commands,
\item In an included file,
\item In a configuration file, provided in the command line or the ANT task.
\end{itemize}
\begin{lstlisting}
@startuml
skinparam classBackgroundColor PaleGreen
skinparam classArrowColor SeaGreen
skinparam classBorderColor SpringGreen
skinparam stereotypeCBackgroundColor YellowGreen
Class01 "1" *-- "many" Class02 : contains
Class03 o-- Class04 : agregation
@enduml
\end{lstlisting}
\begin{center}
\includegraphics[width=50mm]{class_022.png}
\end{center}
% ========================================================================
\newpage \subsection{Skinned Stereotypes}
You can define specific color and fonts for stereotyped classes.
\begin{lstlisting}
@startuml
skinparam class {
BackgroundColor PaleGreen
ArrowColor SeaGreen
BorderColor SpringGreen
BackgroundColor<<Foo>> Wheat
BorderColor<<Foo>> Tomato
}
skinparam stereotypeCBackgroundColor YellowGreen
skinparam stereotypeCBackgroundColor<<Foo>> DimGray
Class01 <<Foo>>
Class01 "1" *-- "many" Class02 : contains
Class03 <<Foo>> o-- Class04 : agregation
@enduml
\end{lstlisting}
\begin{center}
\includegraphics[width=60mm]{class_023.png}
\end{center}
% ========================================================================
\newpage \subsection{Splitting large files}
Sometimes, you will get some very large image files.
You can use the "\texttt{page (hpages)x(vpages)}" command to split the generated
image into several files :
\begin{itemize}
\item \textit{hpages} is a number that indicated the number of horizontal
pages,
\item \textit{vpages} is a number that indicated the number of vertical pages.
\end{itemize}
\begin{lstlisting}
@startuml
' Split into 4 pages
page 2x2
class BaseClass
namespace net.dummy #DDDDDD
.BaseClass <|-- Person
Meeting o-- Person
.BaseClass <|- Meeting
end namespace
namespace net.foo {
net.dummy.Person <|- Person
.BaseClass <|-- Person
net.dummy.Meeting o-- Person
}
BaseClass <|-- net.unused.Person
@enduml
\end{lstlisting}
\begin{center}
\fbox{\includegraphics[width=45mm]{class_024.png}}
\hspace*{4mm}
\fbox{\includegraphics[width=45mm]{class_024_002.png}}
\par
\vskip 4mm
\fbox{\includegraphics[width=45mm]{class_024_001.png}}
\hspace*{4mm}
\fbox{\includegraphics[width=45mm]{class_024_003.png}}
\end{center}