levo

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.

Your recallNot started
Process

How do you decide whether a relationship is aggregation or composition?

Numbers

What is an abstract method, and what follows for the class that contains one?

Key term

Explain the design principle 'encapsulate what varies'.

Questions from this subtopic

Each one with the model answer underneath.

  1. 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. 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. 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. 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. 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. 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.

1Closed book
2Open book
3Closed book

The 3-step method, run for you

Answer cold, learn it, then prove it stuck. Levo tracks the jump between your first attempt and your last.

Fundamentals of Programming
Fundamentals of Data Structures
Fundamentals of Algorithms
Theory of Computation

Cram a whole paper in one sitting

Sort every topic into what you know and what you do not, then drill only the weak ones.

A driver is .
softwarehardwarestorage

Blank Blitz makes facts automatic

Rapid timed gap-fills on the terms and numbers you need to recall without thinking.

AThe integer 5 is 0101.
B0.75 is 1/2 + 1/4.
CThe fraction bits are 1100.

Build It gets the exam shape right

Assemble a full-mark answer from its marking points, in the order an examiner wants them.

Head means the first single element of a non-empty list.
TrueFalse

Test It catches misconceptions

Spot the fault in a statement. The traps are the mistakes students actually make.

721941163128510

Brain Breaks between sessions

Short focus games to reset attention, so the next set lands better than the last.

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.