Skip to content

Commit a61929c

Browse files
committed
Adds example UML class diagram
1 parent 63699cb commit a61929c

1 file changed

Lines changed: 97 additions & 5 deletions

File tree

  • reader/content/high-level-design/representations

reader/content/high-level-design/representations/_index.md

Lines changed: 97 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,17 +25,109 @@ Unfortunately, given the ambitious goals UML tries to achieve, it has become an
2525

2626
## Class diagrams
2727

28-
Class diagrams are the most common form of technical abstraction for software systems. Class diagrams are static representations of the software elements and their relationships within a system. For object-oriented systems class diagrams detail the key classes, fields, and methods within a system and how they relate to each other statically. While class diagrams can contain all program elements, they typically focus on a key subset of elements (especially with respect to fields and methods); this does not mean that only public API should be shown, but also API that are intentionally not private. These diagrams are an excellent abstraction for developers to reason about and discuss various design alternatives. Class diagrams can be translated fairly directly into code skeletons (and vice versa).
28+
Class diagrams are the most common form of technical abstraction for software systems.
29+
Class diagrams are static representations of the software elements and their relationships within a system.
30+
For object-oriented systems class diagrams detail the key classes, fields, and methods within a system and how they relate to each other statically.
31+
While class diagrams can contain all program elements, they typically focus on a key subset of elements (especially with respect to fields and methods); this does not mean that only public API should be shown, but also API that are intentionally not private.
32+
These diagrams are an excellent abstraction for developers to reason about and discuss various design alternatives. Class diagrams can be translated fairly directly into code skeletons (and vice versa).
33+
34+
Classes and interfaces are represented by simple rectangles that detail their names, fields, and methods.
35+
Method and field visibility can be clarified by prepending names with + (public), # (protected), and - (private).
36+
Three primary classes of edges exist in class diagrams. Large hollow arrows represent inheritance relationships.
37+
Dotted lines with simple arrowheads represent dependencies (typically through method calls and field references).
38+
Solid lines with filled diamonds represent composition relationships; these relationships indicate that the class on the diamond-end creates and is primarily responsible for the lifecycle of one or more variables of the linked type.
39+
40+
A common way UML class diagrams are used is to translate a verbal description of a requirement or system component into a potential class diagram.
41+
For example, a class diagram for a system that lets students enroll in course offerings, and instructors manage rosters and grades, could be the following.
42+
43+
{{< figure src="uml-class-enrolment.png" alt="UML Class Diagram modeling course enrolment." >}}
44+
<!-- Mermaid code
45+
46+
classDiagram
47+
direction LR
48+
49+
class Person {
50+
+id
51+
+name
52+
}
53+
54+
class Student {
55+
+enroll
56+
+drop
57+
}
58+
59+
class Instructor {
60+
+assignGrade
61+
}
62+
63+
class Course {
64+
+code
65+
+title
66+
+createOffering
67+
}
2968
30-
Classes and interfaces are represented by simple rectangles that detail their names, fields, and methods. Method and field visibility can be clarified by prepending names with + (public), # (protected), and - (private). Three primary classes of edges exist in class diagrams. Large hollow arrows represent inheritance relationships. Dotted lines with simple arrowheads represent dependencies (typically through method calls and field references). Solid lines with filled diamonds represent composition relationships; these relationships indicate that the class on the diamond-end creates and is primarily responsible for the lifecycle of one or more variables of the linked type.
69+
class CourseOffering {
70+
+offeringId
71+
+term
72+
#capacity
73+
+addEnrollment
74+
+getRoster
75+
}
76+
77+
class Enrollment {
78+
+enrollmentId
79+
+status
80+
-createdAt
81+
}
82+
83+
class EnrollmentService {
84+
+enrollStudent
85+
+dropStudent
86+
-processor
87+
-notifier
88+
}
89+
90+
class PaymentProcessor {
91+
+charge
92+
}
93+
94+
class NotificationService {
95+
+send
96+
}
97+
98+
Person <|-- Student
99+
Person <|-- Instructor
100+
101+
Course *-- CourseOffering
102+
CourseOffering *-- Enrollment
103+
104+
Enrollment ..> Student
105+
Enrollment ..> CourseOffering
106+
107+
EnrollmentService ..> PaymentProcessor
108+
EnrollmentService ..> NotificationService
109+
EnrollmentService ..> Student
110+
EnrollmentService ..> CourseOffering
111+
112+
Instructor ..> CourseOffering
113+
-->
114+
115+
116+
In the UML Class diagram:
117+
118+
* Rectangles represent classes (`Person`, `Student`, `Instructor`, `Course`, etc.).
119+
* Visibility markers are shown: `+` (public), `#` (protected), `` (private).
120+
* Inheritance is modeled with hollow arrows: `Person` is a base class for `Student` and `Instructor`.
121+
* Composition uses filled diamonds: a `Course` composes its `CourseOfferings`, and a `CourseOffering` composes its `Enrollment` records (it owns their lifecycle).
122+
* Dependencies use dotted arrows: `EnrollmentService` depends on `PaymentProcessor` and `NotificationService`, and interacts with `Student` and `CourseOffering`.
31123

32124
<!--
33125
For example, the class diagram below could be used to generate the text that follows.
34126
35127
<img src="./figures/uml-class.png" width="512px" alt="class diagram">
36128
37129
-->
38-
130+
<!--
39131
```typescript
40132
interface IInsightFacade {
41133
addDataset(id: string, content: string);
@@ -61,7 +153,7 @@ class Log {
61153
trace(msg: string) { }
62154
info(msg: string) { }
63155
warn(msg: string) { }
64-
error(msg: string, stack?:Stack) { }
156+
error(msg: string, stack?:Stack) { }
65157
}
66158
67159
class InsightFacadeSpec {
@@ -74,7 +166,7 @@ class QueryControllerSpec {
74166
```
75167
76168
Translating from class diagrams to/from code is fairly straightforward. A more common use case is to translate from a textual description to a potential class diagram. For example the class diagram and high-level descriptions below are different representations of the same task.
77-
169+
-->
78170
<!--
79171
Design a system for drawing UML class and sequence diagrams. Class diagrams should support inheritance, composition, aggregation, and dependency relationships. Sequence diagrams only support sync & async calls and responses.
80172

0 commit comments

Comments
 (0)