skip to content

Object-oriented programming

10 roadmaps100 questionsupdated

Objects as bundles of state and behavior: encapsulation, inheritance, polymorphism and dynamic dispatch, composition, and object identity. Interviewers probe these to see past the syntax.

on this pageshow

guide

overview

~1 min

Object-oriented programming questions look like vocabulary checks and rarely are. Anyone can recite encapsulation, inheritance and polymorphism; interviewers want to see past the syntax of the language you write every day to the design idea underneath, and to hear where that idea stops being checked by a compiler and becomes a promise you keep by hand. From the middle level up, many questions ask how several languages draw the same line differently, because a candidate who understands the concept can place any language's version of it. The hub opens with [objects, state and behavior](/topics/found-paradigms-oop-objects-state-behavior): what an object is, how construction establishes a valid state, and what belongs to the class rather than to an instance. [Encapsulation and information hiding](/topics/found-paradigms-oop-encapsulation) and [abstraction](/topics/found-paradigms-oop-abstraction) cover what an object keeps to itself and what it promises in return. The type relationships come next: [abstract types versus interfaces](/topics/found-paradigms-oop-abstract-type-vs-interface), [inheritance](/topics/found-paradigms-oop-inheritance-is-a), and [polymorphism and dynamic dispatch](/topics/found-paradigms-oop-polymorphism-dispatch), which decides what code a call actually runs. [Composition and delegation](/topics/found-paradigms-oop-composition-delegation) is the main alternative route to reuse, and [coupling and cohesion](/topics/found-paradigms-oop-coupling-cohesion) is the vocabulary for judging either design. [Identity, equality and immutability](/topics/found-paradigms-oop-identity-equality-immutability) deals with sameness and change, two things that go wrong in ordinary code, and a short [SOLID](/topics/found-oop-solid) section ties the five principles to those mechanisms. Start with objects and encapsulation, because every later section assumes an object that guards its own state. Learn dispatch before inheritance: overriding only makes sense once you know which choices are made at compile time and which at run time. Questions run from middle-level distinctions, such as overloading against overriding, to principal-level ones about how much of a principle any language can enforce at all.

primer

A few ideas carry the whole subject. Hold these and most questions below become applications of them rather than definitions to recall. - **An object guards a set of valid states.** It bundles data with the operations allowed to change it, and its real job is keeping that data consistent: the class invariant. Construction has to establish the invariant and every public operation has to leave it true. Most questions about constructors, encapsulation and immutability are asking who could break the invariant, and at which moment. - **A mechanism is not the property it serves.** Access modifiers and accessors are mechanisms. Information hiding is a goal of design: each decision likely to change sits behind an interface that is not. A type can be fully access-controlled and still expose its representation through accessors, its memory layout or the references it hands out. - **Inheritance bundles two relations.** Subclassing reuses an implementation; subtyping promises that the new type can stand in wherever the old one is expected. Substitutability is a behavioural claim about preconditions, postconditions and invariants, while a type checker mostly confirms that member names and types line up, so much of the claim is yours to keep. - **Know what is decided when.** Overriding picks an implementation from the receiving object's runtime type. In statically typed languages, overloading picks one from the static argument types, before the program runs. In many languages field reads and default argument values also follow the declared type. Puzzles about surprising output usually reduce to which of those moments made the choice. - **Reuse has a coupling price.** A subclass depends on its base's representation and on the order in which the base calls its own methods; an object that holds a collaborator depends only on that collaborator's public contract. That is the concrete reason behind the advice to prefer composition, and also why the advice is not a law: holding a part costs forwarding code and loses the base's internal calls reaching your overrides. - **Sameness has two meanings.** Identity asks whether two references denote one object; equality asks whether two objects stand for the same value. An equality relation has to be reflexive, symmetric and transitive and has to agree with hashing, and changing a field that equality reads while the object sits in a hashed collection can make it unfindable. - **Each language mechanises a different slice.** These concepts are older and broader than any one syntax. A language enforces part of an idea in its compiler or runtime, leaves part to convention, and sometimes removes the question altogether. A strong answer names the idea first, then says which part a given language actually checks.

Class invariant
A condition on an object's state that holds whenever no operation on it is in progress; constructors establish it and every public operation must preserve it.
Encapsulation
Bundling state with the operations that read and change it, usually with access control limiting which code may reach that state directly.
Information hiding
Keeping a design decision that is likely to change, such as a data representation, behind an interface so that clients cannot come to depend on it.
Subtyping
A relation between types: a value of the subtype can be used wherever the supertype is expected without callers observing a behaviour they were not promised.
Liskov substitution principle
The rule that a subtype honours its supertype's contract: it accepts at least what the supertype accepts, guarantees at least what it guarantees, and keeps its invariants.
Dynamic dispatch
Choosing which implementation of an operation runs from the runtime type of the receiving object rather than from the declared type of the expression.
Overloading
Several operations sharing one name but differing in parameter types or count; the compiler picks one from the static argument types at each call site.
Overriding
A subtype supplying its own body for an inherited operation, which dynamic dispatch then selects whenever the receiver is an instance of that subtype.
Fragile base class
A change to a base class that is safe in isolation but breaks subclasses relying on its internal behaviour, such as which of its own methods it calls.
Forwarding
Passing a call on to a held object, which then runs with itself as the receiver; the everyday mechanism behind reuse by composition.
Delegation
In the strict sense, handing a call to another object while keeping the original receiver as self, so the delegate's internal calls return to the original.
Coupling
How much one unit depends on another's details; the tighter it is, the more often a change in one forces a change in the other.
Cohesion
How closely the responsibilities inside one unit belong together; a highly cohesive unit has members that change for the same reason.
Sealed hierarchy
A supertype whose set of direct subtypes is fixed and known in advance, which lets a compiler check that a match over the cases is exhaustive.

The sections lean on each other more than their titles suggest. **Objects and encapsulation are the floor.** Every later section assumes an object that owns its state and a boundary callers cannot cross. [Abstraction](/topics/found-paradigms-oop-abstraction) is the same boundary seen from outside: what the object promises, stated as a contract, rather than what it keeps back. **Abstract types, inheritance and polymorphism are one subject from three angles.** An interface or abstract type states the contract; inheritance is one way to claim that a type meets it while reusing code; dynamic dispatch is what makes the claim pay off at a call site that only knows the supertype. The [abstract type versus interface](/topics/found-paradigms-oop-abstract-type-vs-interface) choice is about how much implementation and state a contract should carry, and [inheritance](/topics/found-paradigms-oop-inheritance-is-a) is where carried state turns into the fragile base class problem. **Composition answers inheritance's costs, and coupling measures them.** [Composition and delegation](/topics/found-paradigms-oop-composition-delegation) reuses behaviour through a held collaborator and an explicit call, trading some boilerplate for a narrower dependency. [Coupling and cohesion](/topics/found-paradigms-oop-coupling-cohesion) gives you the words to compare the two designs, and the [dependency direction](/topics/found-paradigms-oop-composition-delegation-dependency-direction) topic lifts the same argument from classes to modules. **Identity and equality cut across everything.** A leaked reference undermines immutability, so they meet encapsulation; equality across a subtype boundary is hard to keep symmetric, so they meet inheritance; and every hashed collection depends on equality being stable. **SOLID is a summary layer.** The [SOLID principles](/topics/found-oop-solid) restate these mechanisms as design rules: single responsibility leans on cohesion, the substitution principle on behavioural subtyping, dependency inversion on dependency direction. Read it last, as a check that you can tie each rule to the mechanism underneath it.

  1. Objects, State & Behavior →

    Start with what an object is: state, the operations that guard it, identity, and how construction makes the first valid state.

  2. Encapsulation & Information Hiding →

    The idea most candidates flatten into private fields and accessors; learn what it protects and why that differs from hiding a decision.

  3. Polymorphism & Dynamic Dispatch →

    Learn what is decided at compile time and what at run time before studying the hierarchies that rely on it.

  4. Inheritance & IS-A →

    With dispatch clear, see what a subtype promises, where reuse-driven hierarchies break, and why closing a hierarchy helps.

  5. Composition & Delegation →

    The alternative to inheritance; compare the two only after you can name what each one couples a class to.

  6. Identity, Equality & Immutability →

    Sameness and change: equality laws, value versus reference semantics, and what immutability guarantees, all frequent sources of real defects.

  • Defining encapsulation as private fields with a getter and setter each; that publishes the representation through methods and hides nothing that is likely to change.

  • Calling an overridable method from a constructor, so a subtype's override can run before the subtype's own state has been set up.

  • Deciding is-a from the real-world taxonomy instead of from behaviour: if a subtype cannot honour every operation of its supertype, substitution fails however natural the hierarchy looks.

  • Assuming an overload is chosen from the argument's runtime type; in statically typed languages overloads are resolved from static types, and single dispatch looks only at the receiver.

  • Reciting prefer composition over inheritance with no reason attached; name the coupling it removes and what forwarding costs instead.

  • Redefining equality without redefining hashing to match, or letting equality read mutable fields, so objects go missing from hashed collections.

  • Returning or storing a mutable collection without a copy; a read-only view still shows later changes, and the other party keeps a handle on your state.

  • Using identity comparison as a faster equality check; it is only correct when each value is guaranteed exactly one canonical instance.

Most design questions in this hub come down to a handful of recurring choices; naming the one in play is often worth more than the final answer. - **Inheritance versus composition.** Inheritance gives reuse and substitutability in one declaration and lets the base's internal calls reach your overrides; it also couples you to the base's representation. Composition keeps the dependency to a public contract, at the price of forwarding code and an explicit seam you have to design. - **Open versus closed hierarchies.** An open hierarchy lets anyone add a new subtype but makes a new operation expensive to add everywhere. A closed one lets the compiler check every case and makes new operations cheap, but adding a case breaks each exhaustive match downstream. - **Mutable versus immutable objects.** Immutable objects can be shared without defensive copies and keep equality stable; each change produces a new object, which costs allocation and copying unless structure is shared. - **Enforced versus conventional guarantees.** Sealing, non-overridable defaults and strict visibility make reasoning and optimisation easier; they also block proxies, test doubles and later extension that nobody anticipated.

A few named shapes recur across the sections; recognising them lets you place an unfamiliar question quickly. - **Template method.** A base class fixes the outline of an algorithm and subclasses fill in steps. It is the shape behind most fragile base class stories, because subclasses come to depend on the order of the base's self-calls. - **Strategy.** Behaviour that varies is held as a collaborator and swapped, which is composition replacing an inheritance hierarchy of one-method variations. - **Decorator and wrapper.** An object holds another of the same interface and forwards, adding behaviour around the call; the place where forwarding and true delegation visibly differ. - **Visitor.** A way to get double dispatch in a single-dispatch language, and the usual answer when the case set is fixed but operations keep growing. - **Factory.** Creation moved behind an ordinary operation so it can hand back an existing object, a more specific type or an error, which dedicated construction syntax often cannot. - **Value object.** A small immutable type compared by value, with equality and hashing defined over its whole state; the standard cure for identity and aliasing bugs.

explore

report an issue with this guide →

questions

100 · 10 sections

Some languages treat a call written as receiver.doThing() as a message the receiver resolves at run time; others compile it into a fixed member call. Contrast the two models using specific languages, and say what each buys and costs.

level: middleimportance: should knowfreq 42%
basics
~20 s

Under messaging (Smalltalk, Objective-C, Ruby, Python) the method name is a runtime value the receiver resolves, so an unknown name reaches a hook: doesNotUnderstand:, method_missing, getattr. Under member calls (C++, Go, Rust) the target is fixed at compile time and an unknown name does not compile.

open as a page

In a delegation-based (prototype) object model, describe what happens when you read a name the object does not have, and what happens when you assign to that same name. Contrast that with lookup in a class-based language, naming specific languages.

level: middleimportance: should knowfreq 46%
basics
~20 s

Reads walk the delegation chain until a holder is found; writes normally do not walk — they create an own property on the receiver that shadows the parent's. So prototype state looks shared until the first assignment, while mutating a prototype's array or object stays shared for everyone.

open as a page

Some languages give object creation dedicated syntax that always yields a fresh instance of exactly the named type; others build objects with ordinary functions. Compare the two using Go, Rust, Python and Java, and say what the dedicated syntax makes impossible.

level: middleimportance: should knowfreq 45%
basics
~20 s

Java's and C++'s new T is pinned to T: it cannot return a cached instance, a subtype, or a failure value, so anything interesting moves into a separate function. Go, Rust and Python's new have no such rule -- construction there is a normal function returning a value, so those abilities need no pattern name.

open as a page

Some languages make the class itself an object that can be stored in a variable, passed as an argument and sent messages; others treat class-level (static) members as namespaced functions with no receiver at all. Compare what a first-class class object buys you, and what the receiver-less model forces you to build instead.

level: middleimportance: should knowfreq 42%
basics
~20 s

Where the class is itself an object — Smalltalk, Ruby, Objective-C, Python's classmethod — class-level code has a receiver, so it is inherited, dispatched, and passable as a value. Java, C++ and C# statics have no receiver, so you inject factory objects or use reflection.

open as a page

A C library's public header contains only `typedef struct Conn Conn;` plus functions taking `Conn *` — the struct itself is defined in a .c file the caller never sees — even though the C language has no access-control keywords at all. Python is similar in spirit: a leading underscore is a convention, `__all__` names the exported surface, and an attribute written `self.__x` inside `class Cls` is simply stored under the name `_Cls__x` so that a subclass will not collide with it. Meanwhile, a class that declares every field private and adds a matching getter and setter for each satisfies every rule a language is able to check. Are encapsulation and information hiding the same thing? Argue using these cases.

level: middleimportance: must knowfreq 55%
basics
~20 s

No. Encapsulation is a mechanism: bundle state with the operations that reach it. Information hiding is a design property: a module keeps a changeable decision secret. A C header can hide everything with no keywords; getter-and-setter classes hide nothing.

open as a page

Between fully private and fully public, languages offer intermediate visibility levels - protected, package-private, assembly-internal, crate-visible. What unit of code does each of these actually trust, and how would you choose one under a least-privilege rule?

level: middleimportance: must knowfreq 55%
basics
~20 s

Each trusts a different unit: subclasses (protected), one flat package (Java package-private), one compiled assembly (C# internal), one compilation module (Kotlin internal), a crate subtree (Rust pub(crate), pub(super)), one package plus the internal directory rule (Go). Pick the smallest unit that still compiles.

open as a page

Java convention says make every field private and add getX()/setX(); Python convention says expose the attribute and reach for @property only if you later need one. Explain what language feature makes these opposite conventions both correct, and what each community pays for its rule.

level: middleimportance: should knowfreq 45%
basics
~20 s

The uniform access principle: in Python, Ruby, C#, Kotlin and Swift a stored attribute can become a computed one without changing call sites, so accessors up front are noise. Java has no properties, so x.field cannot later become a computation - the getter buys future freedom, not encapsulation.

open as a page

Eiffel and Ada 2012 let a type declare an invariant that the runtime checks on your behalf, while Java, Python and C# leave you to re-check by hand in every mutator. For the languages that check automatically, at exactly which moments does the check fire — and why is it deliberately NOT evaluated during a call the object makes on itself?

level: middleimportance: should knowfreq 40%
basics
~20 s

An invariant constrains an object's stable states, not every instant. Eiffel evaluates the class invariant on entry to and exit from qualified calls (x.f); D runs invariant blocks around public member functions; Ada 2012 checks Type_Invariant when a value crosses the package's visible boundary. Internal self-calls are skipped so a routine can legally break and rebuild state.

open as a page

A constructor or setter accepts a mutable object from the caller and stores it. In some languages the caller is left with no usable handle on what it passed; in others it keeps one, and in at least one popular language a copy is made that still shares storage. Explain the mechanisms and where the trap is.

level: middleimportance: should knowfreq 40%
basics
~20 s

Rust moves ownership, so the caller's binding is unusable afterwards. Swift structs copy by value. Go copies a struct but its slice and map fields still point at the same backing storage. Java, C#, Python and JavaScript share by reference unless you copy by hand.

open as a page

A library operation documents that its argument must be a non-empty collection, and a caller passes an empty one. Whose defect is that, and how do Eiffel, Racket, Kotlin and Rust each express and enforce that obligation differently?

level: middleimportance: must knowfreq 40%
basics
~20 s

The caller's. Preconditions are caller obligations. Eiffel's require blames the caller by name, Racket blames the module that crossed the boundary, Kotlin's require throws with no party named, and Rust encodes non-emptiness in the argument type so there is nothing left to check.

open as a page

Languages disagree about who decides that a concrete type satisfies an abstraction: in Java the type's author declares it, in Go the compiler infers it from method shape, and in Rust a third party may be forbidden from declaring it at all. Compare these models and what each one costs.

level: middleimportance: must knowfreq 48%
basics
~20 s

Nominal (Java, C#): the type's author writes implements, so retrofitting a library type needs a wrapper. Structural (Go, TypeScript): matching method shape is enough, so a consumer can define the abstraction afterwards. Rust traits are nominal but either side may write the impl, and the orphan rule forces a newtype when neither is local.

open as a page

You need to add an operation to an abstraction that code outside your control already implements, without breaking those implementations. Compare the mechanisms offered by Java's default methods, C#'s default interface members, Swift's protocol extensions and Go's optional-interface upgrade.

level: seniorimportance: must knowfreq 42%
basics
~20 s

Either add it with a default body or do not add it to the abstraction at all. Java default methods dispatch virtually and an implementer's own method always wins; C# default interface members are visible only through an interface-typed reference; Swift extension members that are not protocol requirements dispatch statically; Go publishes a second small interface and type-asserts for it.

open as a page

A repository operation that hides SQL lets a raw driver failure — a SQLSTATE code, a socket timeout — escape to a business-level caller. Explain why that is an abstraction-level defect, and how different languages' error models push you to fix it.

level: seniorimportance: must knowfreq 55%
basics
~20 s

The caller must now understand the layer it was insulated from, and its own callers inherit that coupling. Java translates and wraps, Go wraps with %w and reopens deliberately via errors.As, Rust converts through From at the ? boundary, Python chains with raise-from, Erlang crashes to a supervisor instead.

open as a page

A collection interface promises "give me the element at position i" for every implementation, but one implementation walks a chain of nodes to answer it. Which languages let a caller see that cost difference through the API itself, and which hide it?

level: middleimportance: should knowfreq 45%
basics
~20 s

Interfaces promise behaviour, not cost, so a linked implementation answers index-at-i in linear time behind the same call. C++ and Rust omit indexing from list types entirely; Scala splits IndexedSeq from LinearSeq; Java only adds a RandomAccess marker.

open as a page

Some languages let a class have two supertypes that share a common ancestor, and others refuse. Explain why inheriting a type, inheriting an implementation, and inheriting state are three separate problems, and show how at least three named languages draw the line differently.

level: middleimportance: must knowfreq 58%
basics
~20 s

Types are only obligations, so they union freely. Implementation conflicts are decidable — pick one, order them, or error. State is the hard layer: a shared ancestor's fields must be duplicated per path or shared, and neither default is right for every program.

open as a page

In several widely used languages the question 'should this be an abstract class or an interface?' cannot be asked in that form at all. Name such languages, say what replaces the choice there, and explain what actually drives the decision instead.

level: middleimportance: should knowfreq 40%
basics
~20 s

Go and Rust have no implementation inheritance, so there is no abstract class: you declare an interface or trait and reuse code by composition or default bodies. In C++ an interface is just an abstract class with only pure virtual functions. Python offers abc.ABC or typing.Protocol.

open as a page

Reusable bundles of methods come in two flavours: ones copied into the composing class so that a name clash is an error you must resolve, and ones inserted into the lookup chain so that composition order decides the winner. Contrast the two models and name languages of each kind.

level: middleimportance: should knowfreq 40%
basics
~20 s

Flattening (Pharo traits, PHP traits, Rust traits): methods are copied in, composition order is irrelevant, and a clash is reported and resolved by exclusion or aliasing. Chain insertion (Ruby modules, Scala traits): the unit becomes a link in the lookup chain, so order decides and forwarding continues along it.

open as a page

Not every abstract type can be used as a runtime-polymorphic reference. Rust rejects `dyn Trait` for a trait whose method is generic or returns `Self`; Swift could not use a protocol with `Self` or associated-type requirements as an existential (`any Protocol`) at all until SE-0309; C# 11's static abstract interface members are reachable only through a constrained type parameter, never through an interface-typed variable; Java has no such rule but also cannot declare `abstract static`. What single underlying rule explains all four, and how do you split an abstract type that breaks it?

level: seniorimportance: should knowfreq 24%
basics
~20 s

An erased reference carries a value plus a fixed table of code addresses, but not the concrete type. Members needing the type — constructors, statics, constants, Self returns, generic methods — cannot cross. Rust, Swift and C# declare them and restrict use; Java forbids declaring them.

open as a page

Your library publishes both an abstract base class that outside teams subclass and an interface they implement. Set aside anything to do with default method bodies on the interface: what does shipping the base class commit you to that the interface does not, and how do the languages you know differ when you later add a concrete method or a data member to that base?

level: seniorimportance: should knowfreq 42%
basics
~20 s

Publishing a base spends every subclass's one inheritance slot and turns its constructors and protected members into API. Later adding a concrete method can silently capture a subclass's own method — silent in Java, a hiding warning in C#, a compile error in Kotlin and Swift.

open as a page

Inheriting an implementation and being usable wherever another type is expected are two different relationships. Which languages let you have one without the other, and what is each mechanism actually for?

level: middleimportance: must knowfreq 55%
basics
~20 s

Subclassing is code reuse; subtyping is substitutability. C++ private inheritance and Eiffel non-conforming inheritance give reuse with no substitutability; Go embedding and Rust default trait methods give reuse without inheritance; Go and TypeScript grant subtyping with no declaration at all.

open as a page

In Go, a struct that embeds another struct gets that struct's methods, yet a promoted method never calls back into a method the outer struct redefines. Name the mechanism Go is missing here, explain why that mechanism is what makes base classes fragile in other languages, and say what Go gives up by not having it.

level: middleimportance: should knowfreq 30%
basics
~20 s

Go embedding has no open recursion: inside a promoted method, the receiver is still the embedded value, so redefining a method in the outer struct shadows rather than overrides. Open recursion — late-bound self-calls — is what turns a base class's internal call graph into part of its contract. Go gives up the template method pattern.

open as a page

When an override calls "the parent version" of a method, languages disagree about which method that actually is. Compare how Python's super(), Ruby's super, Scala's stackable traits and C++'s explicit base qualification pick the target, and what breaks if you assume it is always the lexically named base.

level: middleimportance: should knowfreq 38%
basics
~20 s

Python, Ruby and Scala resolve the parent call dynamically along the receiver's linearized ancestor list, so the target can be a class the caller never mentions. C++ has no super and forces a statically named base. Java, C# and Kotlin bind super to one fixed base.

open as a page

Some languages let a type declare that only a fixed, known set of types may extend or implement it — Java's `sealed ... permits`, Kotlin's `sealed class`, Scala 3's `sealed trait`, Rust's `enum`. What does a compiler gain from that guarantee, and where do these languages actually draw the boundary of "known"?

level: middleimportance: should knowfreq 45%
basics
~20 s

It gains exhaustiveness: the compiler can enumerate the cases, so a match needs no default branch. Where "known" ends differs — the type itself in Rust and Haskell, the file in Scala 3, the package plus module in Java and Kotlin.

open as a page

Switching a class from `extends Base` to merely holding a `Base` as a field takes away more than the inherited methods: a subclass can also read and write the base's `protected` fields (Java's `java.util.Vector` declares `elementData` and `elementCount` that way), while a containing object can only call the base's public API. What does a base class share with its subclasses beyond its public API, why is that sharing almost impossible to take back later, and how do Smalltalk, Java/C++, Scala traits, Go embedding and Rust traits differ in what state a reuse mechanism can carry?

level: seniorimportance: should knowfreq 38%
basics
~20 s

Inheritance shares state, not just code. Protected fields are a second, subclass-facing API you can never narrow, and they freeze the base's representation. Containment reuses no state unless the base publishes accessors — that is the real cost of extend-to-contain.

open as a page

An operation's behaviour depends on the runtime types of TWO objects, not one — for example what happens when two different kinds of game entity collide, or how a document node is rendered onto a particular device. Explain what a single-dispatch language can and cannot decide for you here, and how languages differ in what they offer.

level: middleimportance: should knowfreq 45%
basics
~20 s

Single dispatch consults exactly one runtime type — the receiver — so the second object's runtime type is invisible to selection. Julia and Common Lisp key methods on the whole argument tuple, Clojure lets you name the dispatch function, and elsewhere you bounce through a second call on the other object.

open as a page

You are designing a library API whose surface will be consumed from languages that have no method overloading at all — Go, Python, JavaScript and Objective-C among them. How should you handle operations that would naturally be overloads, and what do overload sets turn into on the other side?

level: middleimportance: should knowfreq 30%
basics
~20 s

An overload set is not a portable API concept — only a name plus an arity survives a boundary. Express variants as distinct names (Go's style), keyword or default parameters (Python), an options object (JavaScript), or argument labels (Objective-C). Never distinguish variants by argument type alone.

open as a page

Parametric, subtype and ad-hoc polymorphism are usually listed as three flavours of one idea. What information does each of them actually use to choose an implementation, and why can some languages select an implementation from the return type while others cannot?

level: middleimportance: should knowfreq 45%
basics
~20 s

Subtype dispatch chooses on the receiver's runtime type. Overloading chooses on the static argument types. Typeclass/trait resolution (Haskell, Rust, Swift) chooses on the whole inferred type, so it can select from the return type. Parametric polymorphism chooses on nothing.

open as a page

In most class-based languages a call like obj.method() is resolved from the object's actual class, while a read like obj.field is resolved from the declared type of the expression obj. Why does state bind to the declared type, and how do the languages that do let a subtype substitute state actually achieve it?

level: middleimportance: should knowfreq 42%
basics
~20 s

A field read is a load at an offset the compiler fixes from the declared type, so there is nothing to reroute. A virtual call is a table lookup, which can be rerouted. Substitutable state must therefore be method-shaped: properties, accessors, descriptors.

open as a page

When a call is resolved from the receiver's runtime type, the runtime needs a table of implementations somewhere. Compare where that table lives in C++, Go, Rust and Ruby, and what each placement makes possible or impossible.

level: middleimportance: should knowfreq 45%
basics
~20 s

C++ and Java store a table pointer inside the object, fixed at construction. Go and Rust store it in the reference (interface value, fat pointer), so a type can be made dispatchable after it exists. Ruby and Objective-C have no table: they look up by message name and cache.

open as a page

Two modules each reference the other, forming a cycle in the dependency graph. What does a cycle actually cost you, and which languages refuse to build one versus merely letting it hurt later?

level: middleimportance: must knowfreq 54%
basics
~20 s

A cycle fuses its members into one unit: everything in a strongly connected component must be built, tested, versioned and understood together. Go rejects import cycles at compile time with no override; Java and C# allow package-level cycles freely; Python allows the import and fails at runtime on a partially initialised module.

open as a page

Modelling notations mark a part whose lifetime is owned by its whole (UML's filled diamond, composite aggregation) differently from a part that is merely shared and can outlive the whole (the hollow diamond). In which languages is that distinction actually enforced by the compiler or runtime, and where is it only a comment?

level: middleimportance: should knowfreq 62%
basics
~20 s

Only where the language has ownership semantics. C++ value members and Rust's move-and-Drop destroy the part with the whole. Swift's ARC leaks if you model it wrong. Under Java, C#, Python or Go a tracing collector frees whatever is unreachable, so the diamond is documentation.

open as a page

Several languages ship built-in help for making one object stand in for another: Kotlin's `by` clause, Scala 3's `export`, Go struct embedding, Ruby's Forwardable/SimpleDelegator, and Python's `__getattr__`. Compare what each of them actually generates, and what each one cannot do.

level: middleimportance: should knowfreq 38%
basics
~20 s

All of them generate forwarding, not delegation. Kotlin by, Scala 3 export and Go embedding emit compile-time stubs that call the inner object; Ruby's Forwardable metaprograms named methods; Python's __getattr__ forwards at run time but is skipped by implicit special-method lookup.

open as a page

The usual textbook claim is that an inheritance relationship is fixed when the class is written, while a contained part can be swapped at run time. In which languages is the first half of that claim false, and what does changing the relationship at run time actually cost?

level: middleimportance: should knowfreq 34%
basics
~20 s

In prototype and dynamic-class languages the link itself is mutable: JavaScript's Object.setPrototypeOf, Python reassigning obj.class or Cls.bases, Ruby's per-object extend and reopened classes. The cost is deoptimization and cache invalidation — and, unlike swapping a part, it changes dispatch for everything reaching that class.

open as a page

An association is navigable in both directions: an order knows its customer and the customer knows their orders. What does maintaining that two-way link actually cost, and why is the same shape far harder in some languages than in others?

level: seniorimportance: should knowfreq 46%
basics
~20 s

Two costs: an invariant (both ends must always agree, so one mutator owns both writes) and a reclamation cost that depends on the runtime. Java, C# and Go collect the cycle for free; Swift and C++ shared_ptr leak unless one end is weak; Rust rejects the shape and pushes you to Weak or index tables.

open as a page

A codebase has a class holding unrelated helpers - string padding, date arithmetic, a retry loop - grouped only because they had nowhere else to live. Classify that grouping, and explain why the same three functions in Python, Go or Rust would usually not produce a class at all.

level: middleimportance: should knowfreq 45%
basics
~20 s

Coincidental cohesion: the members share nothing but a file. Java and C# have no free functions, so the dump must take the shape of a class; Python, Go and Rust let functions live directly in a module, so the same dump is a namespace, not a type.

open as a page

One class reads and writes another class's fields directly instead of going through its methods. Name that kind of coupling, and explain why whether a compiler can even prevent it depends on the language's unit of protection — compare Python, Go, Rust, C++ and Java, including what Java's reflective `setAccessible(true)` still does at runtime on current JDKs.

level: middleimportance: should knowfreq 50%
basics
~20 s

Content coupling — the strongest kind, because the dependent breaks on any internal change. Whether a compiler can stop it depends on the language's unit of protection: per-class in Java, C# and C++, per-package in Go, per-module in Rust, and convention-only in Python.

open as a page

A team breaks a 3,000-line god class into several files using C# partial classes, Ruby class reopening or Objective-C categories, without moving a single member out of the type. Has cohesion improved? Explain what each mechanism actually changes.

level: seniorimportance: should knowfreq 30%
basics
~20 s

No. Cohesion is a property of the member set and the state those members touch; all three mechanisms merge back into one type with one field set. C# partial is a compile-time text split, Ruby reopening makes the member list load-order dependent, and Objective-C categories can collide with no diagnostic.

open as a page

A method takes a boolean parameter that selects which of two behaviours it performs. Name the coupling that creates, and explain how argument labels (Swift, Smalltalk, Python keyword-only parameters) and closed sum types (Rust, Kotlin, Swift enums) each change the diagnosis.

level: seniorimportance: should knowfreq 55%
basics
~20 s

Control coupling: the caller passes a value whose only job is to steer the callee's internal branch, so the caller must know branches it should not. Labels make the flag readable but leave the coupling; only turning the choice into a dispatched, exhaustively checked variant removes it.

open as a page

"If a class is hard to test, it is too coupled" is standard advice. Explain why that probe is far more reliable in Go or Rust than in Python, Ruby or JavaScript, and what a team in the dynamic languages should measure instead.

level: seniorimportance: should knowfreq 35%
basics
~20 s

Python, Ruby and JavaScript can replace any import, method or global at runtime, so a badly coupled unit still tests green and the pain signal is suppressed. Go and Rust have no runtime patching, so substitutability must be designed in and the probe stays honest.

open as a page

The five SOLID design principles (single responsibility, open/closed, Liskov substitution, interface segregation, dependency inversion) were written down for class-based languages with implementation inheritance. Go and Rust have no implementation inheritance at all. For each of the five, name the language mechanism the principle actually spends, say which ones carry over untouched, and explain which one's classic wording has to be restated and why.

level: middleimportance: should knowfreq 45%
basics
~20 s

Single responsibility spends only a unit of change; interface segregation and dependency inversion spend only interfaces — all three carry over untouched. Open/closed's "add a subclass" wording must be restated as "add an implementation". Liskov survives as intent but loses its compiler checks.

open as a page

The substitution principle in SOLID (the "L") asks that a subtype be usable anywhere its supertype is expected without breaking callers written against the supertype. A type checker, however, only verifies shape: names, arity, parameter and return types. How much of substitutability can a language actually mechanise? Contrast Eiffel's inherited contracts with `require else` and `ensure then`, Ada 2012's split between the `Pre` aspect and the `Pre'Class` aspect, Java's and C#'s covariant arrays with their runtime `ArrayStoreException` / `ArrayTypeMismatchException`, and read-only interfaces such as Kotlin's `List` (versus `MutableList`) or C#'s `IReadOnlyList<T>`.

level: principalimportance: nice to knowfreq 26%
basics
~20 s

Type checkers verify shape only: names, arity, types. Behaviour is left to convention. Eiffel and Ada 2012 inherit contracts so a tightened precondition is unwritable; Java and C# instead mechanise an unsound rule, covariant arrays, and patch it with runtime store checks.

open as a page

Teams call a type "immutable" when they may mean one of three different things: that the name cannot be rebound, that the object's own fields cannot be written, or that nothing reachable from the object can change for anyone. Separate those three guarantees, explain why a read-only interface type — such as Kotlin's List, which a MutableList can be upcast to without a copy — delivers none of the third, and say what a language has to take away from the programmer in order to guarantee it.

level: middleimportance: must knowfreq 55%
basics
~20 s

Binding immutability fixes the name; shallow fixes the object's own fields; transitive means nothing reachable can change for anyone. Only transitive enables safe sharing. A read-only interface is just a view — someone may still hold the mutable original.

open as a page

Several languages generate equality and hashing for you from a type's declared members — Kotlin data classes, Scala case classes, C# records and Java records among them. Compare what these generated implementations actually include, and where each one still leaks.

level: middleimportance: should knowfreq 35%
basics
~20 s

They differ on three axes: which members count (Kotlin uses primary-constructor properties only; C# records use all instance fields), the subtype policy (Scala's canEqual, C#'s runtime equality contract, final Java records), and reference members such as arrays, which all four compare by identity.

open as a page

When is it safe to use identity comparison ("are these two references the same object?") as a stand-in for value equality? Name languages where this is a guarantee and languages where it only appears to work.

level: middleimportance: should knowfreq 45%
basics
~20 s

Only when the type guarantees exactly one canonical instance per value. Erlang and Elixir atoms, Lisp and Scheme symbols, Ruby symbols and JavaScript's Symbol.for registry give that guarantee. Java's small-Integer cache and CPython's interned strings do not; they are optimizations.

open as a page

Some languages let you declare a type whose instances are copied whenever they are assigned or passed, while others give every user-defined type reference semantics. Compare the two language models and say what each one costs the programmer.

level: middleimportance: should knowfreq 45%
basics
~20 s

Value semantics: assignment copies the object, so two names never alias one state. Reference semantics: assignment copies a handle. C#, Swift, Go and C++ let the type's author choose; in Java, Python and JavaScript every object is a reference.

open as a page

IEEE-754 specifies that a NaN floating-point value is not equal to itself. Which law of an equivalence relation does that break, and how do different languages' hash containers and sorting routines cope with a value that is not equal to itself?

level: seniorimportance: should knowfreq 28%
basics
~20 s

It breaks reflexivity, the base law. Languages cope differently: JavaScript keys Map and Set with SameValueZero so NaN works as a key; Go accepts a NaN map key you can never read back; Rust withholds the Eq trait, so a float cannot key a hash map at all.

open as a page