Skip to main content

Week 3 Review — OOP Design

Goal

This review checks whether I can design with types, not only define them.

Week 3 topics:

  1. Polymorphism and substitution
  2. Interface vs abstract class
  3. Composition vs inheritance
  4. SOLID on a small backend
  5. Beans, DI, and proxies as OOP

1. Week 3 big picture

OrderService (policy, one job)
has-a OrderRepository (interface) ← JPA proxy or fake
has-a PaymentGateway (interface) ← Stripe or fake
has-a PricingPolicy (interface) ← Regular / Vip
place() may be wrapped by a Spring proxy for @Transactional

Everything I need for the first Spring week is in that drawing: objects, interfaces, composition, substitution, a wrapper.


2. Core memory sentences

Same call, different object, different behavior.

Interface = capability. Abstract class = shared skeleton with state.

Inheritance is is-a. Composition is has-a.

SOLID in Spring: one job per class, extend via implementations, honor contracts, small interfaces, depend on abstractions.

A bean is an object the container constructs and holds.

A proxy is a polymorphic wrapper. this is not the proxy.

I new values. The container news services.


3. Speak these without notes

  1. Program to an interface, with PaymentGateway as the example.
  2. When I choose an abstract class over an interface.
  3. Why I would not extend OrderService to make VIP pricing.
  4. Dependency Inversion as constructor injection.
  5. Why @Transactional on a private method or on this.save() fails.

4. Tiny design proof

Write four types in a throwaway package, no Spring:

  • PaymentGateway + FakeGateway
  • OrderService that accepts PaymentGateway in the constructor
  • A test main that calls place with the fake

Then add LoggingGateway as a decorator around the fake. Same OrderService. That is composition + polymorphism without a framework. Spring will only take over construction.


5. Common mix-ups from this week

Mix-upClear line
Interface for every classInterface when I need a seam or a second implementation
SOLID = more filesSOLID = better reasons to change
Proxy = annotationProxy = object of the same type that delegates
IoC = never newNever new the injectable services
Inheritance shares fieldsComposition shares collaborators

6. Interview drill


7. Ready for the Spring book?

I am ready if I can explain, with the OrderService drawing:

  • why the repository is an interface
  • why the service has private final collaborators
  • why a singleton must not store the current request
  • why a proxy is a subtype or an interface implementation

Start: Book Week 1 Day 1 — What problem does Spring solve?

Java continues with Week 4 — Exceptions. Later weeks (generics, collections, streams, concurrency, modern Java) are outlined in the curriculum.