levo

Fundamentals of Programming

Aggregation, Composition, Class Diagrams and Design Principles

  • 3 things to know
  • Paper 1
Start revising · £5/month

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.

Everything in your subscription

Runs, plus a mode for every other kind of session.

1Flash
2Imposter
3Fade
4Brain dump

Learn every subtopic in runs of four questions

Facts flash and fade, a wrong word hides in some of them, and a brain dump decides which questions are locked in.

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

Cram the night before, weakest topic first

A quick scan finds your weakest topics. Recall each fact you missed three times in a row.

A driver is .
softwarehardwarestorage

Blank Blitz consolidates the facts

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

✓What it iscovered
~Why it happenspartly there
How long it lastsnot there yet

Explain It tests your understanding

Explain a concept in your own words and see which of its points you covered.

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

Test It catches misconceptions

Spot the fault in a statement. The faults are the mistakes students make most often.

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.

Learn it in runs of four questions, each ending on a brain dump against the clock. Every question you lock in comes back the next day, then at longer gaps, each time just before you would forget it.

Or £46 a year, about £3.83 a month. Cancel anytime.