Why OOP Exists
Procedural languages (C) tie data and the functions that act on it loosely together — global data can be changed by any function, anywhere, making large programs hard to maintain and reason about. OOP fixes this by binding data and behavior into a single unit (the class), controlling exactly who can touch what, and modeling programs as a set of interacting objects rather than a sequence of instructions.
Classification / Structure of OOP Concepts (Big Picture)
Use this as the mental map before drilling into definitions — CSS questions often ask you to "classify" or "categorize" OOP concepts, not just define them.
- A. Basic Building Blocks
- Object, Class, Attribute (data member), Method (member function), Message Passing
- B. The Four Pillars (Core Principles)
- Abstraction, Encapsulation, Inheritance, Polymorphism
- C. Object Relationships (how classes relate to each other)
- Association (general "uses-a" link) → Aggregation ("has-a," weak, parts can exist independently) → Composition ("has-a," strong, parts die with the whole) → Inheritance ("is-a")
- D. Binding Types (when a call is resolved)
- Static/Early Binding — resolved at compile time (e.g., function/operator overloading)
- Dynamic/Late Binding — resolved at run time (e.g., virtual functions, overriding)
- E. Design-Quality Metrics (how "good" an OOP design is)
- Coupling — degree of interdependency between classes (aim: low coupling)
- Cohesion — how closely related/focused a single class's responsibilities are (aim: high cohesion)
Glossary of Key OOP Terms (Definitions)
- Object — a runtime instance of a class; a self-contained unit combining state (data) and behavior (methods). Example:
myCar is an object of class Car.
- Class — a blueprint/template that defines the attributes and methods an object of that type will have; no memory is allocated until an object is created from it.
- Attribute / Data Member — a variable that holds an object's state (e.g.,
balance in a BankAccount class).
- Method / Member Function — a function defined inside a class that operates on its data members (e.g.,
deposit()).
- Instance — another word for "object"; "instantiation" is the act of creating an object from a class.
- Message Passing — how objects communicate: one object invokes another object's method, optionally passing data.
- Constructor — a special member function automatically invoked when an object is created; typically initializes data members. Has the same name as the class, no return type.
- Destructor — a special member function automatically invoked when an object is destroyed; used to release resources. Prefixed with
~ in C++.
- Abstraction — exposing only essential features of an object while hiding implementation detail ("what it does," not "how it does it").
- Encapsulation — bundling data and methods into a single unit (class), typically restricting direct access to internal state via access modifiers.