AQA A-Level Computer Science 7517
Fundamentals of Programming
Fundamentals of Data Structures
Fundamentals of Algorithms
Theory of Computation
Fundamentals of Data Representation
Fundamentals of Computer Systems
Fundamentals of Computer Organisation and Architecture
Fundamentals of Communication and Networking
Consequences of Uses of Computing
Systematic Approach to Problem Solving
Fundamentals of Databases
Big Data
Fundamentals of Programming
Aggregation, Composition, Class Diagrams and Design Principles
- 3 things to know
- Paper 1
Overview
Recall questions on aggregation and composition, drawing classes, inheritance and the +, - and # symbols in class diagrams, abstract, virtual and static methods, and the object-oriented design principles.
What you need to know
Answer each one before you reveal it.
What is an abstract method, and what follows for the class that contains one?
Explain the design principle 'encapsulate what varies'.
Questions from this subtopic
Each one with the model answer underneath.
- 1
What is aggregation?
Model answer
A has-a relationship between a whole and its parts in which the parts can exist independently of the whole. The whole holds references to objects that were created elsewhere and that continue to exist if the whole is destroyed. A football team has players, but disbanding the team does not destroy the players, who may join another team.
- 2
What is composition?
Model answer
A stronger has-a relationship in which each part belongs to exactly one whole and cannot exist without it. The whole creates its parts and is responsible for them, and destroying the whole destroys them too. A house is composed of rooms: the rooms are not shared with another house and they cease to exist when the house is demolished.
- 3
How do you decide whether a relationship is aggregation or composition?
Model answer
Ask what happens to the part when the containing object is destroyed, and whether the part can be shared. If the part carries on existing independently, or can belong to more than one whole at once, it is aggregation, as with a library and the members who borrow from it. If the part is owned exclusively and dies with the whole, it is composition, as with an order and its order lines. Both are has-a relationships, so neither is inheritance.
- 4
How are composition and aggregation shown in a class diagram?
Model answer
Both are drawn as a line joining the two classes, with a diamond at the end nearest the containing class, the whole. Composition uses a filled black diamond and aggregation an unfilled white diamond. The diamond is always placed at the whole, never at the part, so which end it is on is as important as its colour.
- 5
Describe how a single class is drawn in a class diagram.
Model answer
As a rectangle divided into three compartments stacked vertically. The top compartment holds the class name. The middle one lists the attributes, each usually with its data type. The bottom one lists the methods, each usually with its parameters and return type. Every attribute and method carries a symbol in front of it showing its visibility.
- 6
What do the symbols +, - and # mean in a class diagram?
Model answer
They are visibility specifiers written in front of an attribute or method: + means public, - means private, and # means protected.
Other ways to work this
The same content, four other ways.
What is inside Levo
Six ways to work the same material.
Every question in Fundamentals of Programming, on a schedule.
Attempt a question from memory, write the correct version, then attempt it again. Levo records the jump between your first attempt and your last, and brings each question back on the day you are due to forget it.
Or £46 a year, about £3.83 a month. Cancel anytime.