Practice Flashcards
What is inheritance?
Track your progress — Sign up free to save your progress and get smart review reminders based on spaced repetition.
All Flashcards in Topic 7.2
Below are all 25 flashcards for this topic. Sign up free to track your progress and get personalized review schedules.
7.2.15 cards
What is inheritance?
Defining a class as a **specialised version** of another, taking its attributes and methods and adding its own.
Inheritance or composition — how do you choose?
Say it aloud. "A SavingsAccount **is an** Account" → inheritance. "A Car **has an** Engine" → composition.
What does super() do?
Calls the **parent's** version — usually the constructor, which sets the inherited attributes. Without it those attributes are never set.
What is overriding?
A child class **redefining** a parent's method. Its version is used for objects of that class only.
Why is inheritance the tightest coupling in OOP?
A child depends on the parent's **internals**, not just its interface, so one change to the parent can break every subclass at once.
7.2.25 cards
What is polymorphism?
The **same call** behaving differently depending on the object it is made on — the caller never asks what type it holds.
Overriding or overloading: same name, different parameters, one class?
**Overloading** — resolved at compile time. Overriding is a child replacing a parent's method, resolved at run time.
What does polymorphism replace?
A type-checking **if-chain**, repeated everywhere the objects are handled — and every copy is a place to forget a type.
What does adding a new subclass cost in polymorphic code?
**Nothing** — it works with existing loops immediately, so no working code is edited and nothing can break.
Is inheritance the same as polymorphism?
No. Inheritance **shares** a method; polymorphism is the same call **resolving differently** per object. Inheritance is usually how it is achieved.
7.2.35 cards
What is abstraction?
Exposing only the operations a caller needs and **hiding how they are done**.
Abstraction or encapsulation?
**Abstraction** decides *what* is exposed (design). **Encapsulation** enforces *how* it is protected (access control).
Why can an abstract class not be instantiated?
Its abstract methods have **no bodies**, so an object of it could be asked to run a method that does not exist.
Abstract class or interface — when do you use each?
**Abstract class** when children share real behaviour and attributes. **Interface** when unrelated classes must offer the same operations.
What is a leaky abstraction?
One where the caller must know **how** it works to use it correctly — saveToMySQL() rather than save().
7.2.45 cards
Composition or aggregation — what is the difference?
Both are has-a. **Composition** owns the part, which dies with the whole. **Aggregation** references a part that exists independently.
What is the survival test?
Delete the whole. If the part still makes sense it is **aggregation**; if it is meaningless it is **composition**.
What is the tell in code?
The whole **creating** the part inside itself → composition. The part **passed in** → aggregation.
Which UML diamond means composition?
The **filled** diamond ◆. A hollow diamond ◇ means aggregation.
Why prefer composition over inheritance?
Looser coupling (interface, not internals), parts swappable at run time, and none of the parent's unwanted members.
7.2.55 cards
What is a design pattern?
A **named, reusable solution** to a recurring problem — a description of a structure and why it works, not a library.
What does the observer pattern do?
Objects **subscribe** to a subject and are notified when it changes. The subject never knows who is listening.
What is the factory pattern for?
Putting the decision of **which subclass to create** in one place, so concrete class names are not scattered through the code.
What is the strategy pattern?
Interchangeable algorithms behind one interface, **selected at run time** — replacing an if-chain that chooses behaviour.
Why is singleton criticised?
It is **global state**: testing becomes hard and the parts of the program that depend on it are hidden.
Topic 7.2 study notes
Full notes & explanations for OOP: multiple classes
Computer Science exam skills
Paper structures, command terms & tips
Want smart review reminders?
Sign up free to track your progress. Our spaced repetition algorithm will tell you exactly which cards to review and when.
Start Free