IB Computer Science HL · Year 2 · Lesson 20

Design Patterns + B3.2 Checkpoint

Explain Singleton, Factory and Observer, then integrate inheritance, polymorphism, abstraction and class relationships in a cumulative HL OOP check.

Paper 250 minutesB3.2.1–B3.2.5 cumulative
Targets

Patterns solve recurring design problems

2 / 11
  • explain Singleton, Factory and Observer as solutions to recurring design problems;
  • select a suitable pattern from a scenario and justify the match;
  • retrieve and apply all B3.2 concepts;
  • complete the planned 2027 case-study checkpoint on GAN training balance and mode collapse.
B3.2.1B3.2.2B3.2.3B3.2.4B3.2.5
Learn + retrieve

Rapid Recall Deck

3 / 11

Attempt each card first. If a term is new, flip and study it, then answer it again without looking. Mark only secure recall as “Know it”.

B3.2.5

Three patterns you must be able to explain

4 / 11

Singleton

Use when: the application should share one coordinated instance, such as one configuration manager.

Risk: global shared state can make testing and dependencies harder if overused.

Factory

Use when: client code needs objects of different concrete types and creation logic should be centralized.

Benefit: calling code depends less on construction details.

Observer

Use when: several listeners must react when one subject produces an event or state change.

Benefit: the subject can notify subscribers without hard-coding each response.

Explain, do not just nameFor B3.2.5, link the pattern to the recurring programming challenge it solves.
Apply

Choose the pattern from the problem, not from the name

5 / 11

Match the design problem

A. A program should create PDFReport, CSVReport or HTMLReport from a requested format without spreading construction logic across the system.

B. A dashboard has several widgets that must update whenever a sensor publishes a new reading.

C. Every part of an application must read the same runtime configuration object.

Name the pattern.
Explain the exact recurring problem it solves.

A: Factory centralizes creation of different report types. B: Observer lets multiple subscribed widgets react to one sensor event. C: Singleton can provide one shared configuration instance when exactly one coordinated instance is required.

Factory pattern

Centralize object creation

6 / 11
class TextReport:
    def build(self):
        return "text"

class PDFReport:
    def build(self):
        return "pdf"

class ReportFactory:
    @staticmethod
    def create(kind):
        if kind == "text":
            return TextReport()
        if kind == "pdf":
            return PDFReport()
        return None

Trace the factory

Predict the type and output produced by:

report = ReportFactory.create("pdf")
print(report.build())

create("pdf") returns a PDFReport object, so the output is pdf. The client requests the kind and does not construct the concrete class directly.

Observer + judgement

Patterns are tools, not rules

7 / 11

Read the Observer structure

class NewsFeed:
    def __init__(self):
        self.subscribers = []

    def subscribe(self, listener):
        self.subscribers.append(listener)

    def publish(self, message):
        for listener in self.subscribers:
            listener.update(message)

Explain the roles of the subject and observers in this design.

NewsFeed is the subject: it stores subscribers and publishes updates. Each listener is an observer expected to provide update(message). One publication can therefore notify multiple independent observers.

Pattern or overengineering?

A script reads one configuration value once and exits. Should Singleton automatically be added because “configuration often uses Singleton”?

No. The pattern should solve an actual recurring design problem. For a tiny one-use script, Singleton may add unnecessary global structure without a meaningful benefit.

Exam lens

Cumulative HL OOP practice

8 / 11

B3.2 cumulative Paper 2 mini-set

1. Explain how inheritance and method overriding can work together to produce dynamic polymorphism.

2. Explain how an abstract class can establish a common interface for subclasses.

3. A Playlist stores references to existing Song objects that can appear in other playlists. Explain the class relationship.

4. A system must notify several displays whenever one data source changes. Explain which design pattern is appropriate and why.

  1. A child inherits the shared interface and overrides a method; a common method call is dispatched at runtime to the implementation belonging to the actual child object.
  2. The abstract class defines required operations while leaving concrete implementations to subclasses, so client code can rely on one interface.
  3. Aggregation: the songs exist independently and are referenced rather than lifecycle-owned by one playlist.
  4. Observer: one subject can notify multiple subscribed displays when the source changes.
2027 Case Study

GAN generator/discriminator balance

9 / 11
2027 Case Study checkpointIn a GAN, a generator produces synthetic images from a D-dimensional noise vector and a discriminator judges real versus generated images. The two networks train competitively. Training can become unstable, and mode collapse can reduce output diversity.

Build a research note: GAN training balance

Generator: what is it trying to improve?
Discriminator: what is it trying to improve?
Imbalance: why can one network becoming too strong stall useful learning?
Mode collapse: what does it look like in generated outputs?
Research next: record one credible mitigation technique/source to investigate before L50–L55.

The generator learns to produce outputs that increasingly resemble real images and deceive the discriminator. The discriminator improves at distinguishing real training images from generated ones. Useful adversarial learning depends on neither side overwhelming the other for long periods; severe imbalance can make training unstable or uninformative. In mode collapse, the generator produces a narrow range of similar outputs instead of capturing the dataset’s diversity. Keep mitigation research evidence for the later deep case-study block.

Progress check

Close the OOP block with evidence

10 / 11

OOP gap diagnosis

Choose one B3.2 area that still needs retrieval: inheritance, polymorphism, abstraction, composition/aggregation or patterns.

IA progress check

Record one implemented feature, one test result and one implementation choice you can justify in Criterion D.

Homework

Finish the learning cycle

11 / 11

IA — main task

Continue Criterion D development/testing and evidence logging. Make sure one implementation decision is explained rather than only described.

Paper 2 — short practice

Redo only the B3.2 checkpoint items you missed. Add one credible research source/mitigation note to the GAN training-balance section of your case-study research.

Checkpoint

Open the 2027 Case Study Hub and verify that your GAN note uses the official terms generator, discriminator, adversarial dynamic, training stability and mode collapse.