Computer Science · Theme B: Computational thinking and problem-solving
B3.2 — Fundamentals of OOP for multiple classes
Computer Science · SL / HL · syllabus-mapped notes
CS_B3.2.1
Inheritance for code reusability
Parent and child class hierarchies, and access to parent members under four modifiers.
Full note — freeThis card is HL only. You must be able to explain and apply inheritance to promote code reusability. Code is required. Parent and child classes Inheritance sets up a hierarchical relationship: a child (sub) class extends a parent (super) class , reusing its attributes and methods and adding or extending functionality, so shared code is written once. Impact of access modifiers on inherited members public : inherited and accessible everywhere, including the child. protected : inherited and accessible inside the child class (and the same package). default (package-private): accessible only within the same package, so a child in another package cannot use it. private : not accessible in the child class; it stays usable only within the parent itself. class Animal: def __init__(self, name): self.name = name def speak(self): return "..." class Dog(Animal): # Dog inherits from Animal def speak(self): # reuses name, extends behaviour return self.name + " barks"
CS_B3.2.2
Modelling polymorphism
Dynamic polymorphism via method overriding, and static polymorphism for efficiency.
This card is HL only. You must be able to construct code that models polymorphism : one interface taking many forms, which contributes to code flexibility and reusability. Code is required. Dynamic polymorphism (method overriding) A subclass supplies its own version of a method already …
CS_B3.2.3
Abstraction and abstract classes
Exposing essentials for modular code, and abstract classes as common interfaces.
This card is HL only. You must be able to explain abstraction : exposing only the essential features of something while hiding unnecessary implementation detail. Significance for modular code Abstraction lets each module be used through a simple interface without knowing its internals, so code …
CS_B3.2.4
Composition and aggregation
Building objects from components, and how the two has-a relationships differ.
This card is HL only. You must be able to explain the role of composition and aggregation : designing an object out of smaller component objects, a "has-a" relationship. Aggregation : a loose has-a relationship in which the subcomponents can function independently of the aggregating …
CS_B3.2.5
Common design patterns
Singleton, factory and observer, and the recurring problems they solve.
This card is HL only. You must be able to explain commonly used design patterns : reusable, proven solutions to recurring programming challenges. Singleton : ensures a class has only one instance and provides a single global point of access to it. e.g. one shared …
