CS fundamentals

OOPs and Design Patterns

Classes, SOLID and the design patterns that show up in machine coding and design rounds.

  • Handwritten-style
  • Diagrams and tables
  • Worked examples

Who this notebook is for

Students and developers preparing for object oriented design questions and machine coding rounds. It suits anyone who has written a few classes and wants the reasoning behind good design.

What you will be able to do

  • Explain the four pillars of OOP with an example for each
  • Apply the SOLID principles to improve a small design
  • Choose between factory, builder, strategy and observer for a given problem
  • Sketch a class design for a small system in an interview

What's inside

Pick a chapter and the notebook opens right there.

  1. Classes, Objects & Memory LayoutStack vs Heap, Object Identity, Value vs Reference, Alignment & PaddingStart here
  2. Encapsulation & Information HidingAccess Modifiers, Invariants, Tell-Don't-Ask, Defensive Copying & Value ObjectsStart here
  3. Abstraction, Interfaces & ContractsAbstract Classes vs Interfaces, Default Methods, Traits/Mixins & ADTsStart here
  4. Inheritance & PolymorphismIS-A vs HAS-A, Overriding vs Overloading, Diamond Problem, Virtual Inheritance & SlicingStart here
  5. Dynamic Dispatch & Vtable InternalsVtable/Vptr Mechanics, Thunks, Double Dispatch, RTTI & JIT DevirtualizationStart here
  6. Object Lifecycle & RAIIConstruction/Destruction Ordering, Move Semantics, Rule of 0/3/5 & Smart PointersStart here
  7. Object Relationships & DemeterAssociation vs Aggregation vs Composition, Law of Demeter, Dependency InjectionStart here
  8. SOLID Principles (Part 1: SRP & OCP)Single Responsibility Actor Analysis, God Object Dismantling, Open-Closed ExtensibilityStart here
  9. SOLID Principles (Part 2: LSP, ISP, DIP)Liskov Substitution, Contract Theory, Role Interfaces & Martin Coupling MetricsStart here
  10. Creational: Singleton & FactoryThread-Safe DCL, Bill Pugh Idiom, Enum Singleton, Factory Method & Static FactoriesStart here
  11. Creational: Abstract Factory & BuilderProduct Families, Fluent Builder, Step Builder Wizard, Prototype & Copy ConstructorsStart here
  12. Structural: Adapter, Facade & DecoratorClass vs Object Adapter, Subsystem Facade, Dynamic Decorator & Java I/O StreamsStart here
  13. Structural: Proxy, Composite & FlyweightVirtual/Protection Proxies, Dynamic Proxies, Recursive Trees & Flyweight RAM OptimizationStart here
  14. Behavioral: Strategy & ObserverRuntime Strategy Swapping, Modern Lambdas, Event Pub/Sub & Lapsed Listener GC LeaksStart here
  15. Behavioral: Command, State & TemplateUndo/Redo Dual-Stacks, Sagas, FSM State Transitions & Template Invariant SkeletonsStart here
  16. Language Internals & Object ModelsHotSpot Mark/Klass Word, Compressed OOPs 32GB Cliff, C++ Fixups, Python __slots__Start here
  17. Low-Level Design (LLD) BlueprintsParking Lot System, O(1) Tic-Tac-Toe Engine, Elevator LOOK Algorithm & Scoring RubricStart here
  18. Master Synthesis & Top 15 Q&A23 GoF Matrix, Top 10 Anti-Patterns, Thread-Safe Concurrency & Senior Tech Round ChecklistStart here

Practice this

Put it to work on LakeBench.

Common questions

Which language are the examples in?
The ideas are language neutral, and the examples use common object oriented syntax so you can follow them in Java, C++ or Python.
Will it help with low level design interviews?
Yes. It builds from classes to patterns and ends with design blueprints you can practise on.
Can I read a sample before I commit?
Yes. The contents pages and the first pages of every notebook can be read online, so you can judge the style before going further.

More in CS fundamentals

All notebooks