Object-oriented design
Design patterns
The patterns that come up most, and the problem each one solves.
In two minutes
One idea to a line
Singleton: exactly one instance with a global access point. It must be made thread safe, and it makes testing harder.
Factory: one place decides which class to create, so callers depend on an interface. Abstract factory creates families of related objects.
Observer: when one object changes, all objects subscribed to it are told (events, listeners).
Strategy: put interchangeable algorithms behind one interface and choose one at run time (for example, different sorting or pricing rules).
Decorator wraps an object to add behaviour without subclassing. Adapter makes one interface look like another.
Slips people make here
Interviewers know them too
Using Singleton as a global variable with a nicer name.
Confusing Strategy (swap an algorithm) with State (the object changes behaviour as its state changes).
Mixing up Adapter (change an interface) and Decorator (add behaviour, same interface).
Your practice here
Not started
12 written questions
No answers yet