← Back to Object-Oriented Programming

Object-Oriented Programming — Quick Summary

Quick revision: every topic, key terms, and mnemonics for Object-Oriented Programming.


This is a quick revision doc covering all 29 topics in the OOP collection — half JavaScript, half Python. Open the linked notes if you want depth. The four pillars (encapsulation, inheritance, polymorphism, abstraction) are spread throughout — pay attention to how each language realizes them.

OOP Pillars (cross-language quick map)

PillarJavaScriptPython
Encapsulation#privateField, closures, WeakMap, _underscore_protected, __mangled, @property
Inheritanceclass Child extends Parent, super()class Child(Parent):, super().__init__()
PolymorphismMethod overriding + duck typingMethod overriding + duck typing + dunder ops
AbstractionThrow in base methods, new.target, factoriesabc.ABC + @abstractmethod, Protocol

Remember. “EIPA — Every Interview Picks A pillar.”

JavaScript

Objects Fundamentals

What it is. Object literals {key: value}. Properties accessed via dot or bracket notation; bracket required for dynamic keys / special chars. Methods are properties whose value is a function.

Key terms.

Constructor Functions & the new Keyword

What it is. Pre-class blueprint for instances. Capitalized name + called with new.

new does 4 things. 1) creates {}, 2) links proto to Fn.prototype, 3) calls Fn.call(newObj, ...args), 4) returns this (unless an object is explicitly returned).

Key terms.

Remember. “new makes object, links proto, runs ctor, returns this.”

Prototypes & the Prototype Chain

What it is. Each object has a hidden [[Prototype]] linking to another object. Property lookup walks the chain until found or until null.

Key terms.

Remember.__proto__ is the link. prototype is the stencil.”

ES6 Classes

What it is. Sugar over constructor + prototype. typeof Class === "function".

Key terms.

Inheritance: extends & super

What it is. class Dog extends Animal { ... }. super(...) calls parent constructor; super.method() calls parent method.

Key terms.

Remember. “super first, this second. Forget super, get ReferenceError.”

Encapsulation & Private Fields

What it is. Hide internals. JS gives several mechanisms.

ApproachTrue privacyWorks with classNotes
#field (ES2022)Yes (engine-enforced SyntaxError)YesModern default
ClosuresYesNo (factory only)No prototype sharing
WeakMapYesYesPre-ES2022 trick
_underscoreNo (convention)YesJust naming
Symbol keysPseudo (findable via getOwnPropertySymbols)YesHidden from Object.keys

Remember.# for new code; closures for factories; everything else is legacy.”

Polymorphism in JavaScript

What it is. Same interface, different behavior.

Key terms.

Remember. “If it has the method, just call it.”

Abstraction Patterns

What it is. Hide complexity, expose a simple interface. JS has no abstract keyword.

Key terms.

Remember. “Don’t abstract until a second implementation actually shows up.”

this Keyword & Execution Context

What it is. Determined by how the function is called.

Decision tree.

  1. Arrow function? → lexical this (from surrounding scope). Can’t be changed.
  2. Called with new? → new instance.
  3. call/apply/bind? → whatever you pass.
  4. obj.method()?obj.
  5. Plain fn()?undefined (strict) / window (sloppy).

Common pitfall. Method passed as callback loses this. Fix: arrow function or .bind(this).

Remember. “Look at the call site, not the definition.”

Getters, Setters & Proxy

What it is.

Remember. Vue 3 reactivity = Proxy. “Getters/setters for one prop; Proxy for all.”

Mixins & Composition over Inheritance

What it is. Inheritance creates rigid trees and the fragile base class problem. Composition mixes capabilities.

Key terms.

Remember. “Inheritance = is-a. Composition = has-a. When in doubt, has-a.”

Symbols & Well-Known OOP Protocols

What it is. Unique primitive used as property keys. Well-known Symbols hook into language-level operations.

SymbolTriggered by
Symbol.iteratorfor...of, spread, destructuring
Symbol.toPrimitive+obj, ${obj}, comparisons
Symbol.hasInstanceobj instanceof X
Symbol.species.map(), .filter(), .then() derived constructors
Symbol.toStringTagObject.prototype.toString.call(obj)[object X]

Remember. Generator method shorthand: *[Symbol.iterator]() { yield ... }.

SOLID Principles in JavaScript

S–O–L–I–D. “Single, Open, Liskov, Interface, Dependency.”

PrincipleOne-linerJS pattern
SSingle ResponsibilityOne class, one reason to changeSplit big class into focused modules
OOpen/ClosedExtend without modifyingStrategy / plugin / each shape calculates its own area
LLiskov SubstitutionSubclasses honor parent’s promisesDon’t override to break fly()
IInterface SegregationSmall focused contractsRole-based mixins (Walkable, Swimmable)
DDependency InversionDepend on abstractionsInject dependencies via constructor

Remember. Penguin can’t fly → restructure (FlyingBird subclass). Don’t throw inside fly().

OOP Design Patterns in JavaScript

Seven core patterns and idiomatic implementations.

PatternCategoryIdeaReal-world
SingletonCreationalOne instance globallyModule exports, Redux store
FactoryCreationalHide creation logicReact.createElement, express()
BuilderCreationalFluent step-by-step (return this)Knex.js
Observer (pub/sub)BehavioralSubscribe + emitEventEmitter, addEventListener
StrategyBehavioralPluggable algorithm (just pass a function)Sort comparators, tax rules
DecoratorStructuralWrap to add behaviorExpress middleware, HOFs
ProxyStructuralControl accessCaching, Vue reactivity

Remember. “Functions are first-class — half the GoF patterns disappear.”

Python

Classes & Instances

What it is. class Foo: blueprint. __init__(self, ...) initializes. __new__ actually creates.

Key terms.

Method Types: Instance, Class & Static

What it is.

MethodFirst argUse
InstanceselfRead/modify state
@classmethodclsAlternative constructors / factories. cls(...) respects subclass.
@staticmethodnothingUtility helper namespaced under class

Remember. “self for me, cls for my class, staticmethod for nothing extra.”

Inheritance & MRO

What it is. class Child(Parent):. super().__init__(...) calls parent.

Key terms.

Remember. “MRO walks left-to-right, kids before parents.”

Encapsulation & Name Mangling

What it is. Three conventions:

NameMeaning
namePublic
_name”Internal — please don’t touch” (convention only). from x import * skips these.
__nameName-mangled to _ClassName__name. NOT private — just renamed to avoid subclass clashes.
__name__Dunders (trailing underscores) are NOT mangled.

The Pythonic way. _attribute + @property for real validation. Don’t reach for __double unless you’re avoiding subclass collision.

Remember. “We’re all consenting adults here.”

Polymorphism & Duck Typing

What it is. Same call, different behavior.

Key terms.

Remember. “If it walks like a duck…”

Dunder Methods Deep Dive

What it is. Hooks into Python’s data model.

Key dunders.

Property Decorators & Descriptors

What it is. @property for clean attribute-style getters; @x.setter and @x.deleter to allow assign/del.

Read-only. Just @property with no setter.

Descriptor protocol. Any object with __get__/__set__/__delete__ is a descriptor. When stored on a class, attribute access goes through it.

Key terms.

Remember. Custom descriptor when reusing the same validation across many fields.

Abstract Classes & ABC

What it is. from abc import ABC, abstractmethod. Subclass that doesn’t implement an abstract method can’t be instantiated → TypeError.

Key terms.

Remember. ABCs raise at instantiation time — early failure is the whole point.

Dataclasses & NamedTuple

What it is. Auto-generate __init__, __repr__, __eq__ from typed fields.

Key terms.

Remember. Dataclass for mutable records. NamedTuple for immutable tuples-with-names.

slots & Memory Optimization

What it is. __slots__ = ("x", "y") replaces per-instance __dict__ with fixed-offset slots. ~3x less memory, faster attribute access.

Trade-offs.

Remember. Use it when creating millions of instances of the same shape.

Composition vs Inheritance

What it is. Same debate as JS, expressed in Python.

Key terms.

Remember. “Default to composition. Use inheritance for true is-a only.”

Metaclasses

What it is. A class whose instances are classes. type is the default metaclass.

Chain. type creates DogDog creates buddy. So type(buddy) == Dog, type(Dog) == type, type(type) == type.

Key terms.

Real uses. Django ORM, SQLAlchemy, ABCMeta, EnumMeta.

Remember. “If you wonder whether you need one, you don’t.” — Tim Peters.

Protocols & Structural Subtyping

What it is. from typing import Protocol. Static duck typing. No inheritance — match the shape, type checker validates.

Key terms.

ABC vs Protocol. ABC = inheritance + runtime enforcement. Protocol = no inheritance + static (or opt-in runtime) checks.

Remember. Repository pattern + Protocol = swap PostgresRepo for InMemoryRepo in tests with zero ceremony.

SOLID Principles in Python

Same five principles, idiomatic Python.

Remember. “Modules + Protocols + first-class functions = SOLID for free.”

OOP Design Patterns in Python

Eight patterns, the Pythonic way.

PatternPythonic implementation
SingletonModule-level instance (preferred) or __new__ override
Factory@classmethod alternative constructors (User.admin(name), from_dict(data))
BuilderFluent chaining: each method return self
ObserverDict of event → list of callbacks; emit(event, *args)
StrategyPass a function as a parameter
Decorator@deco syntax (function or class with __call__)
Iterator__iter__ + __next__, but generators replace most cases
Template MethodABC with concrete run() calling abstract steps (extract → transform → load)

Remember. “Patterns survive in Python — the ceremony doesn’t.”