PrepZone Logo
PrepZone

Factory and Abstract Factory

Centralise object creation when the concrete type should be a detail.

Why this matters

  • Simple factory — detailed pointwise breakdown in the section below.
  • Abstract factory — detailed pointwise breakdown in the section below.
  • CampusOS notifications — detailed pointwise breakdown in the section below.
  • Testing with factories — detailed pointwise breakdown in the section below.
  • Patterns are forces and solutions — name the force before the pattern.
Creational
Factorychoose implementation
Builderstep-by-step assembly
Structural
Decoratorstack behaviour
Facadesimple entry point
Behavioral
Strategyswap algorithm
Observernotify subscribers
Statebehaviour by mode
Pick the family first, then the specific pattern.

Overview

Centralise object creation when the concrete type should be a detail. Study each section below in order — every list is interview-ready reference material.

Simple factory

Points to cover

  • Definition — what Simple factory means in one clear sentence
  • When to use — the force or smell that triggers this concept
  • CampusOS example — where this appears in parking, booking, or library modules
  • How to explain — pointwise bullets you can say aloud in an interview
  • Common mistake — what weak candidates do instead
  • Refactor move — one concrete change that improves the design

Abstract factory

Points to cover

  • Definition — what Abstract factory means in one clear sentence
  • When to use — the force or smell that triggers this concept
  • CampusOS example — where this appears in parking, booking, or library modules
  • How to explain — pointwise bullets you can say aloud in an interview
  • Common mistake — what weak candidates do instead
  • Refactor move — one concrete change that improves the design

CampusOS notifications

Points to cover

  • Definition — what CampusOS notifications means in one clear sentence
  • When to use — the force or smell that triggers this concept
  • CampusOS example — where this appears in parking, booking, or library modules
  • How to explain — pointwise bullets you can say aloud in an interview
  • Common mistake — what weak candidates do instead
  • Refactor move — one concrete change that improves the design

Testing with factories

Points to cover

  • Definition — what Testing with factories means in one clear sentence
  • When to use — the force or smell that triggers this concept
  • CampusOS example — where this appears in parking, booking, or library modules
  • How to explain — pointwise bullets you can say aloud in an interview
  • Common mistake — what weak candidates do instead
  • Refactor move — one concrete change that improves the design
Java
// CampusOS — apply "Simple factory" on paper first, then in code
public final class FactoryAndAbstractFactoryExample {
    // 1. Name entities from the problem statement
    // 2. Draw relationships before writing methods
    // 3. Introduce patterns only when a force appears
}

Quick recall

Everything you need if you only revisit this box.

  1. Simple factory — review this slice before mock interviews.
  2. Abstract factory — review this slice before mock interviews.
  3. CampusOS notifications — review this slice before mock interviews.
  4. Testing with factories — review this slice before mock interviews.

Test yourself

Answer these before moving on — recall is what makes it stick.