B3.1.2 · OOP for a single class
Class design & UML
By the end you can
Design classes and interpret UML class diagrams with visibility modifiers (+, -, #), attributes, and methods.
Before writing code, software architects design object interactions using the. A UML class diagram is a standard graphical representation that specifies the structure, attributes, and methods of classes in an object-oriented system.
The standard 3-compartment class box#
Every class in a UML diagram is represented by a rectangle divided into three horizontal compartments:
- Top compartment (Class Name): The title of the class. Written in PascalCase (e.g.
BankAccount). - Middle compartment (Attributes): Lists internal variables storing the object’s state:
visibility name : type. - Bottom compartment (Methods): Lists executable operations:
visibility name(parameterName : parameterType) : returnType.
Visibility access modifiers#
UML prefixes each member with a single symbol indicating who is allowed to access it:
+(Public): Visible to all classes everywhere. Typically used for public methods (the class’s public API).-(Private): Strictly hidden from external access. All internal variables should be marked private to uphold encapsulation.#(Protected): Accessible within the class itself and any subclasses that inherit from it, but hidden from the general public.
UML Class Diagram & Code Equivalents
Attributes (Variables)
Methods (Operations)
UML Visibility Key
Check yourself
UML class diagrams
Quick questions, made fresh every time and marked here. Do a few until they feel easy.
Exam practice
Paper 1-style questions
3 questions · 9 marks
Write your answer as you would in the exam, then show the mark points and tick each one your answer made. These are our own questions in the style of the exam, not past-paper questions.
1.Describe the three standard compartments of a UML class diagram box, including class name, attributes with data types, and methods with signatures.
[4]Describe: A detailed account: say what happens, step by step if it is a process.
2.State the meaning and symbol for the three standard access visibility modifiers used in UML class diagrams (+, -, #).
[3]State: Give a short answer, no explanation needed.
3.Explain why attributes in a UML class diagram are almost always prefixed with a minus symbol (-).
[2]Explain: Give reasons: say what happens AND why, or how one thing causes another.
In a nutshell
- Unified Modeling Language (UML) class diagrams standardize software architecture blueprints.
- A UML class box has three compartments: class name at the top, attributes in the middle, and methods at the bottom.
- Visibility modifiers control access: + is public, - is private, and # is protected.
- Attribute format: visibility name : dataType; Method format: visibility name(parameters) : returnType.
