OOD & LLD Reference/API & Component Design

Extensible APIs & Plugin Architecture

Open/Closed in practice — plugin registries, dependency injection, strategy injection at construction, and designing for the second use case without rewriting the first.

4/5Overview: 25m

Designing for the second use case

Extensibility means the first feature ships simple; the second feature adds a class, not an edit cascade. Open/Closed at the API layer: stable facade, pluggable implementations.

TechniqueWhen to useExample
Strategy injectionOne behavior variesCheckout(PricingStrategy)
Registry / plugin mapOpen-ended providersMap<String, NotificationChannel>
Factory + interfaceConstruction variesPaymentMethodFactory.create(type)
DI containerMany dependenciesSpring @Autowired list of handlers

Plugin registry pattern

NotificationService holds List<NotificationChannel> or Map<ChannelType, Channel>. register(Channel) called at startup. Adding Slack = new SlackChannel implements NotificationChannel + registration — zero edits to NotificationService.send().

Dependency direction

Inner domain never imports outer adapters (Clean Architecture dependency rule). PaymentProcessor depends on PaymentGateway interface; StripeGateway implements it in the infrastructure layer. Tests inject FakeGateway.

Senior-level signal

Balance OCP with YAGNI: "With one channel, I'd inject a single EmailChannel. At three channels, I'd introduce a registry." Name the extension point (interface + registration) and the stable surface (facade methods callers use). Avoid speculative config frameworks on the whiteboard.

Versioning awareness

When plugins evolve, interface changes break implementors — prefer adding new methods via default interface methods (Java 8+) or a v2 interface. Mention if interviewer asks about backward compatibility.

Where this goes next

Errors, Invariants & Validation covers how extensible APIs stay safe — fail-fast, invariant enforcement, and where validation lives in the object graph.

Further Reading

Practice Tasks (Optional)

Design or implement locally in any language — no autograding. Focus on class structure, extensibility, and being able to explain trade-offs out loud.

  • Plugin design for notifications

    NotificationService sends alerts. Support Email, SMS, Push without modifying NotificationService when adding Slack. Use registry or DI. Draw class diagram and show registerChannel() flow.

    30m