/en-tutor-prep-ib-cs-oop-inheritance-polymorphism-design-patterns/
/en-tutor-prep-ib-cs-oop-inheritance-polymorphism-design-patterns/
General Inquiry: info@TutorZone.com.hk
Office Hours: Monday to Saturday - 9:00 AM to 6:00 PM
WhatsApp Monday to Sunday - 24 hours
Hotline: +852 6828 1809
Instant Support: +852 9061 3106

IB Computer Science: Multi-Class OOP — Inheritance, Polymorphism, Abstraction and Design Patterns (tutor lesson plan; a child class reaches 2 of 4 parent members)

IB Computer Science: Multi-Class OOP — Inheritance, Polymorphism, Abstraction and Design Patterns (tutor lesson plan; a child class reaches 2 of 4 parent members)

  • 2026-11-28

Students can write one class, but ask whether a child class may read the parent balance and the answer stops. Multi-class OOP tests three things: the modifier decides what a child can see, overriding and overloading decide when binding happens, and composition or aggregation decides whether a part can outlive its owner.

Objectives — the student can (1) explain the four access modifiers: of the 4 parent members (2 private, 1 protected, 1 public) a child class reaches 2 directly (50%), and neither private member at all; (2) state what inheritance saves: a 40-line parent plus 8 lines per child gives 56 lines for 3 classes against 144 written separately, saving 88 lines (61.1%); (3) trace dynamic binding: three loan types at 10 days fine 5.0, 10.0 and 20.0, total 35.0, while the parent rate alone would collect 15.0, short by 20.0 (57.1%); (4) separate overriding from overloading: same signature is overriding resolved at run time, same name with different parameters is overloading resolved at compile time, and this chapter has 3 overloads; (5) explain abstract classes: 2 abstract methods implemented by 3 subclasses give 6 implementations and one client loop that needs no change when a fourth type arrives; (6) separate composition from aggregation: deleting an order destroys its 3 lines, deleting a tutor leaves 2 students alive; (7) describe three patterns: singleton (100 calls, 1 object, 198 KB saved), factory (3 types, 12 call sites) and observer (5 observers times 20 events gives 100 notifications).

01 Prerequisites (3-minute check)

If any of these fails, fix it before the lesson starts.

Skill Quick check Pass mark
Classes and objects which of the loan class and Chan’s loan has a real due date? the object
Method signatures may one method name carry two different parameter lists? yes, that is overloading
Percentages what percentage of 35.0 is 20.0? 57.1%

02 Lesson flow (60 minutes)

Time Stage Tutor does Student does
0-8 min Opening check can a child read a parent private member? write an answer first
8-22 min Inheritance and four modifiers 4 members, child reaches 2 fill the access table
22-36 min Polymorphism 10-day fines 35.0 against 15.0 trace three outputs
36-46 min Abstraction 2 abstract methods, 6 implementations write the abstract class
46-54 min Composition, aggregation, patterns 3 order lines, 2 students sort four cases
54-60 min Exit check three questions marked on the spot work alone

03 Teaching script (read it out)

Scene 1: Inheritance and the four modifiers — what a child can see

Open with a real system: a library has loans, and a student loan and a staff loan are both kinds of loan that differ only in the fine rate and the loan period. The parent class declares 4 members: 2 private (the fine rate and the borrower id), 1 protected (the due date) and 1 public (a method returning the period). After a child extends the parent it can use only the protected and public members, 2 of them, which is 50%, and both private members stay out of reach and must be read through a public method.
Build a table with four rows, private, default, protected and public, and four columns: same class, subclass in the same package, subclass in another package, and any other class. Private is the class alone; default allows the package; protected reaches subclasses even from another package; public reaches everyone. Ask for the sentence protected is the channel left open for subclasses and private is not, because that sentence separates the two for good.
Then count the savings: 40 lines in the parent, 8 in the student loan and 8 in the staff loan gives 56 lines with inheritance; written separately each class needs 48 lines for 144 in total, so inheritance saves 88 lines, 61.1%. Make the class say what is saved: the 40 shared lines are written once, not that the code is shorter by a few words.
Close with one test: the child must be a kind of the parent. A student loan is a loan and the sentence works, but a borrower is not a book, so that case needs composition rather than inheritance.

Student task: write out the four parent members with their modifiers and, for each, whether the child can use it directly, then check all four answers against the table.

Scene 2: Polymorphism — overriding is dynamic, overloading is static

Separate the two forms first. Overriding is a subclass rewriting a parent method with the same signature and the method is chosen from the object at run time, which is dynamic binding. Overloading is one name with different parameter lists, chosen from the arguments at compile time, which is static binding. Ask for the shorthand overriding looks at the object and overloading looks at the arguments, then add that overriding needs inheritance and overloading does not.
Trace the fines to show dynamic binding: three loan types override the fine method at 0.5, 1.0 and 2.0 per day, so 10 days give 5.0, 10.0 and 20.0, a total of 35.0. The loop runs three times with no test on the type and still prints three different answers, and that is dynamic binding. Had the parent rate of 0.5 been used, all three would be 15.0, short by 20.0, which is 57.1%, and that arithmetic is the answer to why overriding earns its keep.
Use three versions for overloading: fine(days), fine(days, rate) and fine(days, rate, cap), 3 versions of one name that the compiler tells apart by the argument count. Ask for the benefit, one concept under one name instead of fineWithRate, and the limit, the parameter lists must differ and changing only the return type is not overloading.
Finish with the trade-off: dynamic binding is flexible but needs a run-time lookup, static binding is fixed early and faster. On a question asking which form is resolved at compile time, answer overloading and give that reason.

Student task: write the three overriding methods and one loop that calls them, put the three outputs and the total of 35.0 in a trace table, then add one overloading example.

Scene 3: Abstraction, composition and patterns — keep the change in one place

Start with abstraction. The parent declares 2 abstract methods (compute the fine, return the label) with no body, and the 3 subclasses supply 6 implementations between them. The abstract class exists to fix a common interface: the client knows only that the two methods exist, not which loan it holds. Ask for the benefit, a fourth type means one new subclass and a client loop that does not change, whereas an if-else chain over types must be edited every time. An abstract class cannot be instantiated, only extended.
Then split composition from aggregation with one question: can the part exist without the owner? An order and its lines are composition, because deleting the order destroys its 3 lines and a line without an order means nothing. A tutor and the students are aggregation, because deleting the tutor leaves the 2 students alive with their own life cycle. Ask for the two verbs owns and uses: composition owns, aggregation uses.
Give each pattern a purpose and a number. Singleton: a configuration object must exist once, so the constructor is private and a static method hands out the instance, and 100 calls return 1 object; without the guard the program builds 100 objects of 2 KB each and wastes 198 KB, 99.0%. Factory: 3 loan types are built from a code by one factory, so 12 call sites name no class and a fourth type changes one file. Observer: one subject with 5 observers sends 100 notifications across 20 events without knowing any observer class, only the interface. Ask for the common thread: each pattern takes the part that varies and puts it behind one place.

Student task: classify the four cases (order, tutor, configuration, notification) as composition, aggregation, singleton or observer, and state what happens to the 3 order lines and the 2 students when the owner is deleted.

04 Question types and worked steps

Type Example Steps Answer
Decide whether inheritance fits 4 parent members, two subclasses three steps: say the is-a sentence, list the shared members, leave the rest to the subclass child reaches 2 (50%); both private members stay closed
Trace polymorphic output three loan types at 10 days three steps: read each object type, find that type override, multiply and add 5.0, 10.0, 20.0, total 35.0
Overriding or overloading one fine method with three versions two questions: is the parameter list the same? same means overriding (dynamic), different means overloading (static) 3 overloads; overriding needs inheritance
Composition or aggregation an order with 3 lines, a tutor with 2 students one question: can the part live alone? no means composition, yes means aggregation lines die with the order; students survive
Choose a pattern one instance, build by type, or notify many three questions: unique means singleton, build by code means factory, one-to-many means observer singleton gives 1 object from 100 calls
Sanity check (teach this): five checks: (1) a child can never reach more members than the parent has, 2 of 4, so four of four means private was read as protected; (2) inheritance must save lines, 56 against 144, and a larger figure means the shared parent was missed; (3) the dynamic total must be at least the parent-rate total, 35.0 against 15.0, because no rate is below 0.5; (4) after deleting the owner a composition leaves zero parts and an aggregation leaves more than zero, 3 lines against 2 students, and the two never swap; (5) a singleton leaves exactly one object, 1 from 100 calls, and 100 means the private constructor was forgotten. The usual misjudgement is treating protected and private as the same: protected is for subclasses, private is for the class alone.

05 Independent practice (3 questions)

Question Answer What to watch
a parent class has 4 members (2 private, 1 protected, 1 public). (a) how many can a subclass reach directly? (b) how are the others read? (a) 2, that is 50%; (b) through a public parent method such as the period getter private is not protected; a subclass cannot read it
a loan runs 10 days and the three rates give fines of 5.0, 10.0 and 20.0. (a) what is the total? (b) how much is lost at the 0.5 parent rate? (a) 35.0; (b) 15.0, short by 20.0, which is 57.1% dynamic binding follows the object type, not the declared type
a configuration singleton serves 100 calls, and 5 observers watch 20 events. (a) how many objects exist? (b) how many notifications are sent? (a) 1; (b) 100 a singleton is one, not zero; notifications are observers times events

06 Common mistakes and what to say

Mistake Student writes Say this
Treating a parent private member as inheritable the subclass assigns the parent balance directly private means even the subclass cannot touch it. You may use 2 of the 4 members directly and the rest only through a public method, or encapsulation means nothing.
Calling overloading dynamic the answer says the version is chosen from the object at run time overloading is fixed at compile time from the argument list; only overriding is dynamic. Overriding looks at the object, overloading looks at the arguments.
Using inheritance where composition belongs a student loan extends a student a student loan is not a kind of student, it is a kind of loan. When the is-a sentence fails use composition: the loan holds a student id instead of inheriting the student.
Writing aggregation as composition deleting a tutor deletes the 2 students students have their own life cycle and a tutor leaving does not remove them. Order lines are composition, 3 of them vanish with the order; tutor and student is aggregation and the 2 stay.

07 Homework (paper, section and question numbers)

08 Exit check (last 5 minutes)

Question Answer Decision
Modifiers a parent has 4 members, how many does a child reach? four means private was read as protected
Binding which form is fixed at compile time, overriding or overloading? overriding is the wrong way round
Parts after the tutor is deleted do the 2 students remain? gone means aggregation was called composition

09 Tutor FAQ

Must B3.2 be written in all three languages?

No. Paper 2 uses the one language the school chose, Java or Python. What is assessed is the concept and the trace: the modifier effect, the overriding and overloading split, and the composition or aggregation judgement.

How many design patterns must be memorised?

the guide names three: singleton, factory and observer. For each, state the recurring problem and one example: one instance (100 calls, 1 object), building by code (3 types), and one-to-many notification (100 sends).

How are protected and default marked in UML?

UML uses four symbols: # protected, ~ default or package visible, – private and + public. This parent has two -, one # and one +, so the child sees the # and the +.

Find a tutor — freeTutor Registration →

A TutorZone lesson-prep guide. Written by the TutorZone team; questions and lesson flow are original and are not taken from any school or publisher material.

Join as a tutor or coach — academic, music, sports, arts, STEM. Free to register. See how it works →