Object-oriented programming and SOLID principles – Server Side interview prep
261 interview-style multiple-choice questions on Object-oriented programming and SOLID principles, organized by topic: concepts, scenarios, code to read and tradeoffs, each with a short explanation. Learn the 149 key terms with the flashcards first, then test yourself.
Take the practice test · Flashcards · All study tools
What it covers
- 13.1 Core OOP concepts
- 13.2 Classes, objects and lifecycle
- 13.3 Inheritance and its pitfalls
- 13.4 Composition, delegation and interfaces
- 13.5 SOLID in practice
- 13.6 Polymorphism and type systems
- 13.7 Modeling domains with objects
- 13.8 Clean code principles
- 13.9 OOP across languages and design interviews
Key terms
13.1 Core OOP concepts
- Encapsulation
- Hiding data behind methods
- Polymorphism
- One interface, many implementations
- Coupling
- Degree of dependency between modules
- Cohesion
- How closely a module's parts belong together
- Four pillars
- Encapsulation, abstraction, inheritance, polymorphism
- Abstraction
- What to expose
- Message passing
- Objects send messages
- Object
- State, behavior, identity
- Information hiding
- Hide decisions likely to change
- Interface
- Contract without implementation
- Abstract class
- Shared code, can't instantiate
- Abstract method
- No body; subclasses implement
- DTO
- Data carrier, no behavior
- Invariant
- Always-true condition
- Design by Contract
- Pre/postconditions, invariants
- Prototype-based OOP
- Objects inherit from objects
13.2 Classes, objects and lifecycle
- Constructor
- Puts object in a valid state
- Static member
- Belongs to the class
- Identity vs equality
- Same object vs same value
- Equality contract
- Reflexive, symmetric, transitive
- Mutable hash key
- Lost after field change
- Immutable object
- State never changes
- Wither
- Returns a modified copy
- Defensive copy
- Copy inputs and outputs
- Aliasing
- Two references, one object
- RAII
- Resource tied to object lifetime
- Rule of zero
- Let members manage resources
- Move semantics
- Transfer instead of copy
- friend
- Access to private members
- Property
- Field access with logic
- Two-phase init
- Separate init() call
13.3 Inheritance and its pitfalls
- Composition
- Building objects out of other objects
- Fragile base class
- Base class changes breaking subclasses
- God class
- Class with far too many responsibilities
- Law of Demeter
- Talk only to immediate collaborators
- virtual/override
- Opt-in overriding
- Method hiding
- new modifier, static binding
- Yo-yo problem
- Bouncing through a deep hierarchy
- Self-use problem
- Base methods calling overridables
- Design for inheritance
- Or prohibit it
- Virtual inheritance
- Shared diamond base
- Virtual destructor
- Safe delete via base pointer
- Object slicing
- Derived parts dropped on copy
- Upcast/downcast
- To base / to derived
- White-box reuse
- Inheritance sees internals
- Subclass explosion
- One class per combination
- Field hiding
- Fields aren't polymorphic
- open
- Kotlin opt-in inheritance
- NVI idiom
- Final public method, protected hook
13.4 Composition, delegation and interfaces
- Has-a vs is-a
- Field vs subtype
- Delegation
- Forward work to a held object
- Class delegation
- Generated forwarding
- Trait
- Reusable method set
- Duck typing
- Works if methods exist
- Protocol
- Structural typing for checkers
- Marker interface
- Empty tagging interface
- Program to an interface
- Depend on abstractions
- Aggregation vs composition
- Shared vs owned lifetime
- Self problem
- Callbacks bypass the wrapper
- Explicit interface implementation
- Member only via interface
- Capability interface
- IReadable, IWritable
- Pure virtual function
- = 0
- Protocol-oriented programming
- Protocols with extensions
- Role object
- Roles gained and lost
13.5 SOLID in practice
- SRP
- Single Responsibility Principle
- OCP
- Open/Closed Principle
- LSP
- Liskov Substitution Principle
- DIP
- Dependency Inversion Principle
- SRP actor
- One group requesting changes
- Strategic closure
- Close against likely changes
- Strengthened precondition
- LSP violation
- Weakened postcondition
- LSP violation
- History constraint
- Subtype can't break base's state promises
- Behavioral subtyping
- Substitutable behavior
- Fat interface
- Too many members
- Client-owned interface
- Shaped by users
- Inverted ownership
- Policy owns abstraction
- SOLID acronym
- Coined by Michael Feathers
- Common Closure Principle
- Change together, package together
- Acyclic Dependencies Principle
- No package cycles
- Stable Dependencies Principle
- Depend toward stability
13.6 Polymorphism and type systems
- Subtype polymorphism
- Overriding
- Parametric polymorphism
- Generics
- Ad hoc polymorphism
- Overloading, type classes
- Dynamic dispatch
- Method chosen at runtime
- vtable
- Table of function pointers
- Single dispatch
- Receiver type only
- Double dispatch
- Two runtime types
- Multiple dispatch
- All arguments' types
- Generic constraint
- Required capabilities of T
- Expression problem
- New types vs new operations
- Monomorphization
- Specialized code per type
- CRTP
- Static polymorphism via templates
- Megamorphic call site
- Many shapes, slower
- Coercion
- Implicit conversion
- Gradual typing
- Optional checked annotations
13.7 Modeling domains with objects
- Responsibility-driven design
- Knows, does, collaborates
- CRC card
- Class, Responsibilities, Collaborators
- Information Expert
- Give work to the class with the data
- Creator
- Container creates its parts
- Controller
- First object handling a system event
- Protected Variations
- Stable interface around change
- Pure Fabrication
- Invented class for good design
- Illegal states unrepresentable
- Types prevent bad combos
- Unit-aware type
- Quantity with units
- Parse, don't validate
- Validated types carry proof
- First-class collection
- Wrapper owning collection rules
- Object Calisthenics
- Strict OO practice rules
- Impedance mismatch
- Objects vs tables
- Functional core
- Pure logic, I/O at edges
- Association class
- Relationship with its own data
- Layer supertype
- Shared base per layer
13.8 Clean code principles
- DRY
- Don't Repeat Yourself
- YAGNI
- You Aren't Gonna Need It
- Refactoring
- Improving structure without changing behavior
- Guard clause
- Early return for special cases
- Command-query separation
- Change state or return a value
- Flag argument
- Boolean parameter smell
- Parameter object
- Groups related parameters
- Data clumps
- Values that travel together
- Why comments
- Explain reasons, not lines
- Least astonishment
- Behave as expected
- Hidden side effect
- Unexpected extra action
- Empty collection
- Return instead of null
- Fail fast
- Stop early on bad state
- Speculative generality
- Unused flexibility
- Rule of three
- Abstract on the third copy
- Wrong abstraction
- Worse than duplication
- Cyclomatic complexity
- Independent paths
- Cognitive complexity
- How hard to understand
- Explaining variable
- Named condition
- Deep module
- Simple interface, much behind it
13.9 OOP across languages and design interviews
- UML generalization
- Hollow triangle arrow
- UML visibility
- + - # ~
- Multiplicity
- 1..*, 0..1
- Sequence diagram
- Messages over time
- @property
- Method as attribute
- Name mangling
- __x becomes _Class__x
- abc.ABC
- Abstract base class
- MRO
- C3 linearization
- data class
- Generated equals, copy
- object declaration
- Singleton
- Case class
- Immutable, pattern-matchable
- Open classes
- Reopen any class
- Simula 67
- First OO language
- ECS
- Entities, components, systems
- Data-oriented design
- Cache-friendly bulk data
- Metatable
- Lua's route to objects
- Implicit interface
- Every class defines one
Sample practice questions
What is encapsulation?
- Hiding an object's data behind methods so its invariants hold
- Inheriting behavior from more than one base class
- Converting objects to JSON for storage or transport
- Putting every class in a separate file of its own
Answer: A. Hiding an object's data behind methods so its invariants hold A `BankAccount` exposes `Deposit` and `Withdraw`, not a public `balance` field.
What is a constructor's main job?
- To put a new object into a valid state, with all its invariants satisfied
- To register the object with a global list of all live instances
- To free the memory used by the object once it's no longer needed
- To decide which subclass the object should become at runtime
Answer: A. To put a new object into a valid state, with all its invariants satisfied After construction, the object should be ready to use.
What is the fragile base class problem?
- A base class that doesn't declare any methods at all
- Subclasses that are too small to justify their existence
- A base class that fails to compile on newer compilers
- Base class changes break subclasses relying on its internals
Answer: D. Base class changes break subclasses relying on its internals Deep inheritance trees amplify this risk.
What does the "Tell, don't ask" principle suggest?
- Always ask the user for confirmation before performing any action
- Avoid method parameters, so callers can't pass unexpected values
- Expose a public getter for every single field of every class
- Tell objects to act on their own data instead of pulling it out to decide
Answer: D. Tell objects to act on their own data instead of pulling it out to decide It keeps behavior next to the data it uses.
Which situation violates the Liskov Substitution Principle?
- A `Dog` class that correctly implements every member of `IAnimal`
- An interface that declares exactly one method and nothing else
- A `Square` subclass of `Rectangle` whose `SetWidth` also changes height
- A class that keeps all of its fields private behind properties
Answer: C. A `Square` subclass of `Rectangle` whose `SetWidth` also changes height Subtypes must keep the behavior callers expect from the base type.
Which three kinds of polymorphism are usually distinguished?
- Static, dynamic and hybrid polymorphism based on the compiler
- Public, protected and private polymorphism based on access level
- Single, double and triple polymorphism based on parameter count
- Subtype (overriding), parametric (generics) and ad hoc (overloading)
Answer: D. Subtype (overriding), parametric (generics) and ad hoc (overloading) Coercion is sometimes listed as a fourth kind.
What does responsibility-driven design, from Rebecca Wirfs-Brock, focus on?
- Which database tables each object maps to, designed before any behavior
- Assigning each class to one developer who is responsible for it
- Writing the user interface first and deriving objects from its screens
- What each object knows and does, and which objects it collaborates with
Answer: D. What each object knows and does, and which objects it collaborates with It treats objects as role players, not data holders.
What does DRY stand for, and what does it really target?
- "Debug, Run, Yield": the standard order of steps when fixing a bug
- "Do Repeat Yourself": duplicating code on purpose to keep it readable
- "Don't Repeat Yourself": one authoritative home for each piece of knowledge
- "Delete Redundant YAML": removing duplicated keys from config files
Answer: C. "Don't Repeat Yourself": one authoritative home for each piece of knowledge Merging code that only looks alike can couple unrelated things.
In a UML class diagram, what does a solid line with a hollow triangle arrowhead mean?
- A database foreign key, pointing from child table to parent table
- A method call, pointing from the caller to the class it calls
- Inheritance (generalization), pointing from the subclass to the base class
- Composition, pointing from the part to the whole that owns it
Answer: C. Inheritance (generalization), pointing from the subclass to the base class A dashed line with a hollow triangle means implementing an interface.
What is polymorphism?
- Code written against a base type works with many concrete types
- Copying objects between processes via serialization
- Changing a variable's declared type while the program runs
- A single class declaring a large number of different fields
Answer: A. Code written against a base type works with many concrete types Calling `shape.Area()` works for circles and squares alike.
More Server Side
- HTTP fundamentals
- REST API design
- GraphQL
- gRPC & real-time APIs
- OAuth 2.0, OIDC & JWT
- Sessions, cookies & web app security
- C# & .NET
- Java & Spring Boot
- Node.js & Express
- Python, Django & FastAPI
- Go (Golang)
- Concurrency & multithreading
- Design patterns
- Dependency injection
- Logging & observability
- Data structures
- Algorithms & Big-O
- Linux & shell scripting