Week 3 Review — OOP Design
Goal
This review checks whether I can design with types, not only define them.
Week 3 topics:
- Polymorphism and substitution
- Interface vs abstract class
- Composition vs inheritance
- SOLID on a small backend
- 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.
thisis not the proxy.
I
newvalues. The containernews services.
3. Speak these without notes
- Program to an interface, with
PaymentGatewayas the example. - When I choose an abstract class over an interface.
- Why I would not
extend OrderServiceto make VIP pricing. - Dependency Inversion as constructor injection.
- Why
@Transactionalon aprivatemethod or onthis.save()fails.
4. Tiny design proof
Write four types in a throwaway package, no Spring:
PaymentGateway+FakeGatewayOrderServicethat acceptsPaymentGatewayin the constructor- A test
mainthat callsplacewith 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-up | Clear line |
|---|---|
| Interface for every class | Interface when I need a seam or a second implementation |
| SOLID = more files | SOLID = better reasons to change |
| Proxy = annotation | Proxy = object of the same type that delegates |
IoC = never new | Never new the injectable services |
| Inheritance shares fields | Composition shares collaborators |
6. Interview drill
- Java fundamentals: interface vs abstract class; composition vs inheritance
- Spring Core: IoC, DI, beans
- How to answer: 60–90 seconds, trap, judgment
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 finalcollaborators - 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.