CSSE1001 — Week 10 Notes

Advanced Inheritance

Lecture 10B. See csse1001 for course logistics, python-inheritance for the full reference, now extended with abstract base classes and MRO, and 2025-10-07-uml for the UML notation the diagrams below use.

Outline

  • A useful trick for Assignment 2: type(c).__name__
  • Abstract base classes (and, optionally, the abc module)
  • Method Resolution Order (MRO), and the four inheritance models
  • The diamond problem, and C3 linearisation
  • super() and MRO

A useful trick for A2: getting the class name of an object

class Car():
    pass

c = Car()

print(type(c))
print(type(c).__name__) # e.g., can be used in __repr__

type(c).__name__ returns the class name. The two prints give <class '__main__.Car'> and Car.

So type(c).__name__ is the class name as a plain string. It is handy inside a __repr__ (see python-dunder-methods), which then stays correct even if the class is renamed or subclassed. The equivalent spelling from inside a method is self.__class__.__name__, used in the abc example below.

Abstract base classes

It is common to have an abstract base class that doesn’t have concrete methods/attributes, but enforces contracts in its children classes. You’re not meant to instantiate objects from these abstract classes directly.

Example: an abstract Shape class has an area() method without a concrete implementation. Every (concrete) child class of Shape must provide a concrete implementation of area(). Abstract base classes can sometimes have concrete implementations for some of their methods too (especially if those are meant to be used as-is by child classes).

import math

# Abstract class -- defines the interfaces (child classes must implement these methods)
class Shape:
    def area(self) -> float:
        raise NotImplementedError("Subclasses must implement area()")

    def perimeter(self) -> float:
        raise NotImplementedError("Subclasses must implement perimeter()")

class Circle(Shape):
    def __init__(self, r: float):
        self.r = r
    def area(self) -> float:
        return math.pi * self.r * self.r
    def perimeter(self) -> float:
        return 2 * math.pi * self.r

class Rectangle(Shape):
    def __init__(self, w: float, h: float):
        self.w, self.h = w, h
    def area(self) -> float:
        return self.w * self.h
    def perimeter(self) -> float:
        return 2 * (self.w + self.h)

The abstract class is an ordinary class whose methods carry a full signature (including the -> float return annotation) but no body, only a raise. That signature is the contract; the raise is what makes breaking it noisy. The Shape version above is a plain-Python convention, not an enforced restriction:

Shape() on its own raises nothing at all, because Shape is still just a regular class. The NotImplementedError only fires later, on Shape().area(). Nothing actually stops you from instantiating Shape; only from usefully calling its unimplemented methods.

Optional: enforcing this properly with abc

This part is optional content and non-examinable. The standard-library abc module does enforce the contract at instantiation time:

from abc import ABC, abstractmethod

class Shape(ABC):
    @abstractmethod
    def area(self) -> float:
        ...
    @abstractmethod
    def perimeter(self) -> float:
        ...
    # (optional) concrete helper: allowed in an abstract class
    def describe(self) -> str:
        return f"{self.__class__.__name__}"

With this version, Shape() itself raises a TypeError at the point of instantiation. The abstract methods are enforced immediately, rather than only failing later when called. The exact wording of the message varies by Python version. describe() is the kind of concrete method an abstract base class can have: a real body in an otherwise abstract class, inherited as-is by any concrete subclass.

Two parents with the same method name

If a class inherits from two parents, and both parents have a method with the same name, which one does Python use?

Method Resolution Order (MRO)

MRO stands for Method Resolution Order — it defines the order in which Python looks through classes to find a method or attribute when it’s called on an object. It determines which method gets called when there are multiple implementations, and is stored in cls.__mro__.

Python supports several inheritance models. One running example covers all four: classes A, B, C, D, E.

Single inheritance

A class inherits from a single parent class. This listing is from the course notes. A inherits from object, the universal class:

>>> class A(object):
...     def __init__(self, x):
...         self.x = x
...     def f(self):
...         return self.x
...     def g(self):
...         return 2 * self.x
...     def fg(self):
...         return self.f() - self.g()
>>> a = A(3)
>>> a.x
3
>>> a.f()
3
>>> a.g()
6
>>> a.fg()
-3

B overrides exactly one method. First, B in a flattened form: every method B responds to, written out, with a comment saying where each one actually comes from:

>>> class B(A):
...     def __init__(self, x):              # inherit from A
...         self.x = x
...
...     def f(self):                        # inherit from A
...         return self.x
...
...     def g(self):                        # override
...         return self.x ** 2
...
...     def fg(self):                       # inherit from A
...         return self.f() - self.g()

That is the effective class. The code you actually write is only the one line that differs:

>>> class B(A):                             # inherit from A
...     def g(self):                        # override
...         return self.x ** 2
>>> b = B(7)
>>> b.x
7
>>> b.f()    # inherited from A
7
>>> b.g()    # overridden
49
>>> b.fg()   # inherited from A, but uses B's overridden g()
-42

b.fg() is the one to study: fg is A’s code, unchanged, but the self.g() inside it dispatches on the runtime class, so it finds B.g. 7 - 49 = -42.

Multilevel inheritance

A class inherits from a child class, which in turn inherits from another parent class. It forms a linear chain of inheritance, creating a parent → child → grandchild relationship.

Flattened view of C, with the same kind of comments:

>>> class C(B):
...     def __init__(self, x, y):           # extend from B from A
...         super().__init__(x)
...         self.y = y
...
...     def f(self):                        # inherit from B from A
...         return self.x
...
...     def g(self):                        # inherit from B
...         return self.x ** 2
...
...     def fg(self):                       # extend from B from A
...         return super().fg() * self.y

There is a third category here. B only ever inherited or overrode; C extends __init__ and fg: it calls up to the parent with super() and then does more. For multilevel inheritance the MRO is simple: it just follows the chain from child to parent to grandparent. Here super() is B.

>>> c = C(3, 5)
>>> c.x
3
>>> c.y
5
>>> c.f()    # inherited from B, from A
3
>>> c.g()    # inherited from B (overridden there)
9
>>> c.fg()   # extends B's fg: (3 - 9) * 5
-30

Hierarchical inheritance

Multiple child classes inherit from a single parent class. D is A’s second child, and it overrides a different method from the one B overrode:

>>> class D(A):                             # inherit from A
...     def __init__(self, x):              # inherit from A
...         self.x = x
...
...     def f(self):                        # override
...         return -2 * self.g()
...
...     def g(self):                        # inherit from A
...         return 2 * self.x
...
...     def fg(self):                       # inherit from A
...         return self.f() - self.g()

And, as with B, the code actually written is just the one method that differs:

>>> class D(A):                             # inherit from A
...     def f(self):                        # override
...         return -2 * self.g()
>>> d = D(3)
>>> d.x
3
>>> d.f()   # overridden: -2 * g() = -2 * 6
-12
>>> d.g()   # inherited from A
6
>>> d.fg()  # inherited from A, uses D's overridden f(): -12 - 6
-18

Three of the four models now fit in a single UML diagram:

Figure 1: The running example so far: navy single-compartment boxes and the course’s filled inheritance arrowhead. Every edge on its own is single inheritance; A having two children is hierarchical; the A-B-C chain is multilevel. The two purple labels name the hierarchical and multilevel models.

Who defines what

The four listings as one table. Every B, C and D cell restates the comment on that method in the flattened view; A defines all four itself:

Method A B C D
__init__ defines inherits extends (super()) inherits
f defines inherits inherits overrides
g defines overrides inherits (from B) inherits
fg defines inherits extends (super()) inherits

Multiple inheritance

A class inherits from multiple parent classes:

>>> class E(B, D):   # inherit from B and D
...     pass

B and D sit above E. Add A back in above them and the shape gives the problem its name.

The diamond problem

  • E inherits from both B and D.
  • B and D both inherit from A.
  • Which version of A’s methods should E use?
  • Python resolves this with the MRO C3 linearisation.

Figure 2: The diamond. The small magenta sketch beside it shows where the name comes from. The magenta numbered badges are E’s method resolution order, as given by E.__mro__, which continues to object after A.

C3 linearisation

Three rules:

  • Child classes are checked before parents.
  • Parents are checked in the order they are listed in the class definition.
  • If a class appears multiple times in the MRO, only the last occurrence is kept.

Two ways to inspect the result:

>>> E.mro()                          # Method 1: mro() method
[<class '__main__.E'>, <class '__main__.B'>,
 <class '__main__.D'>, <class '__main__.A'>,
 <class 'object'>]

>>> for cls in E.__mro__:            # Method 2: more readable format
...     print(cls.__name__)
E
B
D
A
object

E defines nothing at all, so every call walks the MRO from the front:

>>> e = E(3)   # which method will be called?
>>> e.x
3
>>> e.f()
-18
>>> e.g()
9
>>> e.fg()
-27
Call MRO walk Resolves to Value
e.x E, B, D — none of them defines __init__; A does A.__init__ → self.x = x 3
e.f() E no, B no, D yes D.f → -2 * self.g() -18
e.g() E no, B yes B.g → self.x ** 2 9
e.fg() E no, B no, D no, A yes A.fg → self.f() - self.g() -18 - 9 = -27

Python resolves each name independently by walking the MRO. It does not pick one winning parent and take everything from it. e.f() lands in D and e.g() lands in B, and then A’s untouched fg calls both of them back through self.

A larger example, showing the general C3 rule in action:

>>> class A: pass
... class B: pass
... class C(A): pass
... class D(A, B): pass
... class E(C, D, B): pass
... print([cls.__name__ for cls in E.__mro__])
['E', 'C', 'D', 'A', 'B', 'object']

A is reachable through both C and D, and B both directly from E and through D. Applying the three rules — children before parents, bases in listed order, keep only the last occurrence of a repeat — gives E, then C, then D, then A (D lists A before B), then B, then object. The example exercises multiple inheritance.

super() and MRO

The super() function follows the MRO, not just the immediate parent:

>>> class A:
...     def ping(self):
...         print("A")
... class B(A):
...     def ping(self):
...         print("B")
...         super().ping()
... class C(A):
...     def ping(self):
...         print("C")
...         super().ping()
... class D(B, C):
...     def ping(self):
...         print("D")
...         super().ping()
>>> D().ping()
D
B
C
A

D’s MRO is [D, B, C, A, object]. When B.ping() calls super().ping(), it does not jump straight to A — B’s statically-declared parent — it calls the next class in the actual runtime MRO of the instance, which is C. This is what makes cooperative multiple inheritance work: each class’s super() call advances one step through the shared MRO, regardless of what its own declared parent is.

Figure 3: Why super() in B lands on C, for the D(B, C) hierarchy. The class boxes and filled inheritance arrows are the course’s UML notation. The magenta badges give the print order D B C A, and the dashed magenta arrow is the delegation made by super() in B.

If a class in the chain doesn’t call super() at all, the chain of calls simply stops there — the MRO itself is unaffected (it’s purely a function of the inheritance structure), but fewer ping() implementations actually get executed. For example, if B.ping() omits its super().ping() call, D().ping() only prints D and B — C and A are never reached, even though they’re still part of D’s MRO.

Summary

When a class inherits from multiple parents, it’s possible for more than one parent to define the same method or attribute. To avoid confusion and ensure consistency, Python uses a rule called Method Resolution Order (MRO) to determine the order in which classes are searched. MRO follows a well-defined path based on class hierarchy and inheritance order, ensuring that each method or attribute is found in a predictable and logical way. This is especially important in complex inheritance situations like the diamond pattern.

Next: design patterns and MVC (2025-10-14-model-view-controller, Week 11).

Unified Modelling Language (UML)

See csse1001 for course logistics — this note covers Lecture 10A’s technical content. See uml for the full reference on UML diagram notation, and csse1001-diagram-notation for the drawing conventions this course actually uses.

Outline

  • Recap: inheritance vs. composition
  • What UML is for
  • UML class diagrams: the three-part class box, and visibility
  • Relationship diagrams: inheritance, association, multiplicity, composition, aggregation
  • A larger, real-world example

Recap: inheritance vs. composition

Feature Inheritance Composition
Relationship “Is-a” “Has-a”
Flexibility Less flexible (changes in parent affect children) More flexible (components can be changed)
Reusability Extends base class functionality Contains objects that provide functionality
Example Dog is a Animal Drone has a Camera

See 2025-09-23-inheritance and 2025-09-23-composition for where these two came from.

What UML is for

Each person on a team asks a different question about the same design: “What classes?”, “Who calls what?”, “Where to pass this?”, “When you pass a drone object to…”. A diagram answers these questions cheaply. Source code answers them expensively.

A unified modelling language diagram is the standard way of illustrating relationships among classes. For our Animal class, the simplest possible version is four name-only boxes: Animal on top, with Cat, Dog and Fox beneath it, joined by one arrow pointing up into the parent.

UML class diagram

A class diagram is a type of UML diagram that shows:

  • Classes and their attributes/methods.
  • Relationships (e.g. inheritance, composition, association).

It is great for object-oriented design.

The class box

A class box has 3 parts, plus a visibility marker on every attribute and method:

  • Top section: class name (e.g. Animal).
  • Middle section: attributes (e.g. name: str).
  • Bottom section: methods (e.g. speak(): str).
  • Visibility: - (private), + (public), # (protected).

Figure 4: The three-part class box: a generic template on the left and the concrete Animal box on the right, outlined in magenta. The purple italic labels name the three parts of the box: name, attributes and methods.

Two details of the notation:

  • An empty compartment is kept, not collapsed. Cat has no attributes of its own, and its box still has a (blank) attributes band. It does not drop to a two-part box.
  • Return types are optional. The same method can be written +info(): str or bare +info(). The difference means nothing.

UML inheritance diagram

Each subclass inherits from Animal and overrides speak(). Inheritance is drawn as a solid line with a filled triangular arrowhead pointing up into the parent, with orthogonal (right-angle) routing: one stem up from a horizontal bus, and a vertical drop to each child.

WarningThe arrowhead is filled, not hollow

Textbook UML draws generalisation with a hollow triangle. CSSE1001 draws it solid filled, on every inheritance arrow. A diagram that matches the textbook does not match the course. Follow the course. See csse1001-diagram-notation.

Figure 5: The inheritance diagram for Animal and its three subclasses. Cat, Dog and Fox each override speak(); Fox also overrides info(). Magenta marks the inheritance relationship, and the purple box in the corner is the legend for its arrow. The arrowhead is filled, the lines run through an orthogonal bus, and Cat’s attribute compartment is kept although it is empty.

Association, multiplicity, composition and aggregation

Four more relationships can be added to the same Animal/Cat/Dog/Fox tree, one at a time. Figure 6 shows the four additions, each drawn in magenta.

Figure 6: The four non-inheritance relationships, each with its name and symbol in purple on the left; multiplicity has a name and no symbol. Association - Cat drinks Milk. Multiplicity - Animal and Vet, 1..* at both ends, labelled Associated. Composition - Animal has exactly one Heart, filled diamond at the Animal end; the dashed filled-head arrow beneath the diamond symbol is a second symbol with no name. Aggregation - an Owner has 0..* Animals, hollow diamond at the Owner end. Each fragment attaches to the Animal/Cat/Dog/Fox inheritance tree of the previous figure, which is unchanged and so is not repeated.

Association

Association — a plain solid line, no arrowhead — represents one class using or knowing about another, without owning it. The example is a Cat that can drink(Milk): Cat gains a +drink(Milk) method, Milk is a class of its own with -expiration: str and +is_fresh(int): bool, and the line between them carries the verb label drinks at one end.

Multiplicity

Multiplicity shows how many objects are involved in a relationship. The vocabulary:

Multiplicity Meaning
0..1 Zero to one
n Specific number
0..* Zero to many
1..* One to many
m..n Specific number range

The example is Animal 1..* —— Associated —— 1..* Vet: an animal can see one or more vets, and a vet treats one or more animals. The counts sit above the line, next to the end they qualify; the verb sits below it.

Composition

Composition (“has a”, filled diamond at the whole end): the “part” cannot exist independently of the “whole”. An Animal has exactly one Heart — 1 at both ends — and the Heart class carries a single attribute -age.

Aggregation

Aggregation (hollow diamond at the whole end) is a weaker form of composition: the “part” can exist independently of the “whole”. An Owner (-name: str, -pets: [], +feed(), +add_pet()) has 0..* Animals, but an Animal exists perfectly well with no owner.

The mnemonic that falls out of the two diagrams: the diamond always sits at the end that owns, and it is filled when destroying the whole destroys the part.

Exercise

Try modelling a UML diagram for the DroneFlight class (from 2025-09-23-composition) and its child DeliveryDrone class (from 2025-09-23-inheritance’s exercise).

A larger example

Real systems combine all of these. The diagram below has thirteen classes, and it is the only whole-system class diagram in the course. Going by the class names (Battlefield, Tank, Player, Enemy, Guard, Patrol), the system is a simplified tank-battle game.

Figure 7: The tank-battle system diagram, with its multiplicities. Dashed arrows are associations/dependencies (WTController to WTView and WTModel; WTModel to Battlefield and Tank; Battlefield to Tile); solid arrows are inheritance. Both heads are solid: the dependency head is a filled concave-backed arrow, the inheritance head the course’s filled triangle. csse1001-diagram-notation describes the dependency head as open. The boxes are single-compartment with pastel fills, not the three-part black boxes above. The fill colours have no stated meaning.

Reading it off the diagram:

  • One WTController is associated with one WTView and one WTModel.
  • One WTModel is associated with one Battlefield and with N Tanks.
  • One Battlefield is associated with N Tiles, and Tile is specialised into Floor, Wall and Rock.
  • Tank is specialised into Player and Enemy; Enemy is further specialised into Guard and Patrol — a three-level chain, which is the multilevel inheritance pattern taught in the very next lecture.

The WTModel/WTView/WTController split is the Model-View-Controller pattern covered in 2025-10-14-model-view-controller. The naming and the direction of the arrows show it: the controller depends on both, and the model depends on neither.

Summary

UML is a visual language used to design and describe software systems. In object-oriented programming, class diagrams are one of the most-used UML tools. They help represent the structure of a system by showing classes, their attributes and methods, and the relationships between them — such as inheritance, association, aggregation, and composition. Using UML before writing code makes it easier to plan, communicate, and maintain software designs effectively.

Next: 2025-10-07-advanced-inheritance (Lecture 10B).

Reference material

CSSE1001 Diagram Notation

This note records the drawing conventions CSSE1001 actually uses, inferred from its own lecture slides. It is the reference that later diagrams in this course should be checked against.

ImportantThis course ships no notation guide

There is no written style or notation standard anywhere in the CSSE1001 materials. The course profile lists no prescribed textbook and no drawing guide; the “Learning resources” section points only to the UQ Library, Blackboard and Ed Lessons. Every convention below is inferred from the drawings themselves, not quoted from a rule.

The three exceptions — places where the slides state a rule in words rather than merely demonstrate one — are the naming conventions (see Naming and capitalisation) and the one figure-source note in 12b. Everything else is observation.

How to read the citations

Decks are cited by their lecture code and PDF page number, e.g. 10a p7 = the UML deck, seventh page of the PDF.

Do not cite the printed footer numbers. They are unreliable: 09a runs 1/14 … 4/39, 5/39, 6/14 … 15/14, 16/15 and then ends on a page footed 14/14 that is actually PDF page 17. Several decks have footer totals that disagree with their own length (11a’s last page reads 14/13). PDF page index is the only stable address.

Colours were sampled from the rendered pages, quantised to 16 levels per channel, so hex values are accurate to roughly ±8 per channel.

What I sampled

248 pages read as images, out of 726 across 25 decks — 17 of the 25 decks. Full text was extracted from all 25 decks plus the course profile, and every deck was scanned for embedded raster images, so the unread decks were checked for figures even where I did not read them.

Deck Pages read
01a history-of-computing 22–33
02a python-memory-model 4–28
03a functions 23–28
03b sequence-selection-and-iteration 2–19
04b non-primitive-data 2–17
07a exceptions 14–21
07b scope 5–19
07c object-oriented-programming 2–19
08a dunder-methods 2–5
08b representation-invariants 5–14
09a composition 1–17 (all)
09b inheritance 1–19 (all)
10a uml 1–14 (all)
10b advanced-inheritance 1–20
11a model-view-controller 1–14 (all)
12a recursion 2–15
12b complexity-and-sorting 2–19

Not read as images: 00-welcome, 01b python-as-a-calculator, 02b primitive-data, 04a while-loops, 05a for-loops, 05b comprehensions, 06a string-methods, 06b file-io. An image-extraction scan across all decks found zero embedded raster images in seven of those eight (00-welcome has six photo pages), and they are typeset in the same LaTeX Beamer template as the decks I did sample. So the risk that they hide an unseen diagram idiom is low but not zero — the eight decks above are the blind spot in this note.

The two slide families

Almost every visual inconsistency in this course traces back to one fact: the decks come from two different production pipelines, and many decks mix both on adjacent pages.

LaTeX Beamer family — serif body text (Computer Modern), ruled code listings with line numbers, coloured named block headings, no raster images. Covers 01b, 02a, 02b, 03a, 03b, 04a, 04b, 05a, 05b, 06a, 06b, and most of 07a/07b/12a/12b.

PowerPoint family — sans-serif labels, filled colour boxes, drop shadows, stock photography, dark-theme code screenshots. Every deck carrying Based on slides from Dr. Azadeh Ghari-Neiat on its title page (07a, 07b, 07c, 08a, 08b, 09a, 09b, 10a, 10b, 11a) contains PowerPoint-family pages.

Consistency: this split holds across the whole semester and is the single most useful thing to know before drawing anything for this course.

Colour palette

These five colours carry meaning and recur across many decks. Everything else is decorative.

Colour Sampled Means Evidence
Dark blue #3030B0 Slide title 10a p4, p7, p10; 09a p12; 10b p10, p19
Magenta #E00080 Defined term, emphasis, the answer 10a p4; 02a p6; 12a p2
Purple #92278F Named block heading; margin annotation 03b p4; 12b p19; 09a p12; 10b p13
Green #109050 (LaTeX) / #00B050 (PPT) A prompt to the student 02a p5; 03b p11; 10a p12; 11a p8
Red #F00000 Warning / failure path 12a p10; 07b p13; 04b p14

Purple #7030A0 is a different purple. It is used only for the UML legend boxes (10a p7, p8, p10, p11) and for the Warning heading in 07b p6. Do not conflate it with the block-heading purple.

Consistency: the blue/magenta/purple/green assignments hold from week 2 (02a) to week 12 (12b). Red is the least consistent — see Inconsistencies.

Named block headings

LaTeX-family slides open a block with a coloured heading on its own line, no box and no rule.

  • Green — a prompt the student is meant to act on: Question (02a p5, 12b p3, p9, p12), Exercise (03b p11, p14; 12b p5, p8, p11, p15; 09b p17; 10a p12; 11a p8), Example (02a p22, p24, p25), Task (07b p17).
  • Magenta italic — the resolution: Answer (02a p6, p7, p8, p9, p23; 12b p18).
  • Purple — a formal or named block: Definition (…) (03b p4, p6, p7, p12; 04b p3; 07c p5; 12b p19), Proposition (12a p13), Base Case / Induction Hypothesis (12a p14), Observe (03b p10), Summary / Next (02a p28, 07a p21, 07b p19), Constants (07b p5), and named algorithms Insertion Sort / Bubble Sort / Merge Sort / Quick Sort (12b p3, p6, p9, p12, p16).

Definition blocks are parenthesised with the term being defined: Definition (Boolean domain), Definition (Predicate), Definition (List), Definition (Complexity).

Consistency: green/magenta/purple hold across at least five decks spanning weeks 2–12. The Warning heading is the exception.

Section divider slides

A section break is a slide bearing one large magenta italic serif word, left-of-centre and high on the page, with a short parenthetical gloss beneath it in small black roman type.

  • Variables — (Named memory locations.) — 02a p14
  • Sequencing — (Order of instructions matters.) — 02a p21
  • Selection — (Controlling program flow.) — 03b p2
  • Lists — (Mutable Ordered Collections.) — 04b p2
  • Memes — (Recursions through meme examples.) — 12a p3

When a deck runs a numbered series of dividers, they take Roman numerals with a colon, and the series continues across decks:

  • I: Structure — (Holding named attributes.) — 07c p8
  • II: Methods — (Object scoped functions.) — 07c p15
  • III: Magic — (Overloading built-in functions.) — 08a p5

Consistency: strong — six plain dividers across four decks, plus a three-part numbered series spanning two decks. One divider (08b p11, Exercise) carries no gloss.

Code listings

Code is by far the most frequently drawn thing in this course, and its presentation is a notation in its own right.

Ruled block. A listing is bounded by a horizontal rule above and below, full text width, with no vertical rules and no background fill. Line numbers run in tiny grey type in the left margin. Code is monospace with visible letter-spacing.

REPL vs. file. The two are distinguished by prompts, not by styling:

  • A REPL transcript uses a magenta >>> prompt for the first line of an input and a magenta ... for continuation lines; output follows on its own line with no prompt (02a p13, p15–p20; 03b p5, p8, p13, p15–p18; 04b p4–p13; 07b p5–p16; 10b p9, p11, p15, p18).
  • A file or definition is shown with line numbers but no prompts at all (04b p15, p16, p17; 08b p6, p9, p13, p14; 09a p10–p14).

Colour inside code. Black is the default. Magenta marks the token or line under discussion — class names being introduced (Battery, Camera, Motor, 09a p10, p11), the lines inherited or overridden (10b p10, p13, p17), the assert keyword (08b p6, p9), the constant being referenced (08b p13, p14). Boolean operators are coloured by identity: and in cyan, or in green, held consistently through 03b p9, p10, p11, p14.

Vertical ellipsis. Elided code is a centred ⋮ on its own line (03a p23) or three stacked full stops (07a p15).

Placeholder metasyntax. Things the student must substitute are written in angle brackets in monospace: <code> and ExceptionName_k (07a p15, p16), <object_variable>.<method>(<parameters>) (07c p16), <statement that should be true> (08b p5). Consistency: three decks.

Annotating code

This is the course’s real “diagram” vocabulary — it annotates listings far more often than it draws figures.

Right-margin note. A short purple italic serif phrase, right-aligned, on the same line as the code it comments on. Sampled #92278F in both 09a p12 and 10b p13 — identical colour, three decks apart. (Measured by histogram at 300 dpi. The neighbouring aside on 09a p13 is #92268F, one unit off in green and blue — the same ink to the eye, but the two pages are not bit-identical.)

Examples: inherit from A, override, extend from B from A, Super is B (10b p10, p13, p14, p17, p18); Drone has-a Battery (09a p12); this is the memory location where 42 is stored (02a p13); Note addition happened first (03b p5); ys is an alias of xs, Aliasing relationship broken! (04b p13); a ‘private’ variable, this is called a ‘getter’ (07c p19); unreachable if line 5 errors (07a p14).

Consistency: the strongest single convention in the course — present in 02a, 03b, 04b, 07a, 07b, 07c, 09a, 10b. Weeks 2 through 10.

Boxed token. A thin rectangle drawn around an identifier inside the listing, marking the thing being named. The box colour is not fixed: purple around Point() and self (07c p9, p16), magenta around raise ZeroDivisionError (07a p18), blue around Child and purple around Parent (09b p9). See Inconsistencies.

Brace grouping. A magenta right-brace } spanning consecutive lines, with a magenta italic label beside it — Attributes beside the two self.x = 0 / self.y = 0 lines (07c p9). Single instance.

Pointer arrow. A straight or gently curved arrow from an annotation to the code element it refers to. Magenta in 07c p12 and p16; orange in 09b p12 and p13; blue and purple in 09b p9.

Colour keying. Where an annotation has a coloured box and a coloured arrow and a coloured word in the caption, all three share one colour: on 09b p9 the blue box round Child, the blue arrow, and the word “Child” in the caption are all blue, and Parent is purple throughout. Two instances (09b p9, p12); treat as a good practice rather than a settled rule.

Focus markers. Small green right-pointing triangles in the far-left margin flag the lines the reader should look at (07b p7, p12). Two instances, one deck.

Scope boxes

The clearest original notation in the course, in 07b.

A rounded rectangle drawn over a span of code lines delimits a scope, and its colour names the scope kind:

  • Purple outline, no fill — global scope; encloses the whole snippet (07b p7, p12).
  • Blue outline, pale blue fill — local/function scope; encloses the def body only (07b p7, p9, p12).

Nesting is literal: on 07b p7 and p12 the blue local box sits inside the purple global box.

Each box is paired with a short horizontal arrow leading out to a colour-matched label — purple arrow to purple global variable, blue arrow to blue local variable (07b p7, p8, p9, p12).

Consistency: four pages of one deck, entirely self-consistent. Never reused elsewhere in the semester.

UML class diagrams

The formal UML vocabulary is taught in 10a and reused once in 10b p19.

Class box. A black-outlined rectangle in three compartments, separated by full-width horizontal rules: name (centred, serif) / attributes / methods (both left-aligned). 10a p6 states the rule in words and shows it twice.

Visibility prefixes. Stated explicitly on 10a p6: - private, + public, # protected. Applied consistently on 10a p7–p11: #name: str, -breed: str, +speak().

Attribute typing. name: type with a Python type — #age: int, -nationality: str, -pets: [] (10a p6, p9, p11). Methods show a return type only sometimes: +info(): str (10a p6) but bare +info() (10a p7–p11).

Empty compartments are kept. Cat on 10a p8–p11 keeps a visibly empty attributes compartment rather than collapsing to two compartments.

Single-compartment boxes are acceptable when only structure is being shown — 10a p4 and 10b p19 draw name-only boxes.

Relationship symbols

Relationship Symbol Evidence
Inheritance Solid line, solid filled triangular arrowhead, pointing up into the parent 10a p4, p7–p11; 10b p19
Association Plain solid line, no head, optional verb label at one end 10a p8 (drinks), p9 (Associated)
Composition Solid line, filled diamond at the “whole” end 10a p10
Aggregation Solid line, hollow (white-filled) diamond at the “whole” end 10a p11
WarningThe inheritance arrowhead is filled, not hollow

Standard UML draws generalisation as a hollow triangle. This course draws it solid filled, verified at 600 dpi on 10a p7 and again on 10b p19. Every inheritance arrow in the course is filled. If you conform to standard UML you will not match the slides; if you match the slides you will not match standard UML. Follow the course.

Line routing is orthogonal. All relationship lines use right-angle elbows, never diagonals (10a p8–p11). A parent with several children gets a single vertical stem down from the parent to a horizontal bus, with vertical drops to each child (10a p4, p7–p11; 10b p19).

Layout and flow. Parent above, children in a row beneath. A grandchild hangs directly below its own parent with its own vertical arrow (10b p19: C below B). Associated non-hierarchy classes sit to the side at the same height as the class they attach to (10a p9 Vet, p10 Heart, p11 Owner).

Multiplicity. Placed above the line, adjacent to the end it qualifies, in magenta — 1..* at both ends (10a p9), 1 and 1 (10a p10), 0..* (10a p11). 10a p9 gives the vocabulary in a legend box: 0..1 zero to one, n specific number, 0..* zero to many, 1..* one to many, m..n specific range.

Magenta marks the relationship being taught. On each of 10a p7–p11 the relationship introduced on that slide is drawn in magenta while previously-established structure reverts to black. On p7 the inheritance tree is magenta; by p8 it is black and the new association line is magenta. Consistency: holds on all five relationship slides — a deliberate, reusable device.

Legend box. A rounded rectangle with a purple #7030A0 outline, containing the relationship name in purple and the bare symbol drawn beneath it, parked in the top-left corner (10a p7 Inheritance, p8 Association, p10 Composition, p11 Aggregation). The multiplicity legend on 10a p9 uses the same box for a text list instead of a symbol.

Non-UML class and object diagrams

Before UML is taught in week 10, the course draws classes at least four other ways. These are not variants of one style — they are four unrelated idioms.

(a) Uniform blue hierarchy — flat steel-blue #4F81BD filled rectangles, white sans-serif labels, parent above and children in a row, joined by a #3D6696 orthogonal bracket with no arrowhead at all — a darker shade of the box fill, not black, though it reads as black at slide size. Photos of instances sit below each child. (09b p2, p3)

(b) Multi-colour hierarchy — parent box black with white text; each child a different Office-palette fill — and these are the stock Office 2007 accents exactly, which is why they recur: #C0504D brick red, #4BACC6 teal, #F79646 orange, #215968 dark teal, olive. Connectors are thin #4A7EBB straight lines — diagonal from the outer children, vertical from the one directly beneath — and each ends in its own arrowhead. On 09b p5 three arrowheads overlap on Animal’s bottom edge; at slide size they read as one, but there are three. (09b p4, p5, p6)

Black for the root holds in all three of these diagrams (Employee, Animal, Person). The child colours carry no meaning I can find — Dog stays teal on 09b p5 even though it is itself a parent.

(c) Attributes-over-methods box — the class name in purple bold sans-serif above two stacked magenta-outlined boxes: attributes on top, methods beneath, with a photo of an instance alongside. (07c p6, three times: Dog, Student, Smartphone)

(d) Attributes-left / methods-right — the class in a black-outlined box in the centre with its name in black and (class) beneath in magenta; a purple-outlined attributes box to the left and a magenta-outlined methods box to the right, each with a plain black label above it. Instances are photographs below, reached by straight black downward arrows with solid heads. (08a p2)

NoteInstantiation arrows point down; inheritance arrows point up

08a p2 draws class → instance as a downward arrow. Every inheritance arrow in the course points up to the parent. The two are never shown on the same page, so the contrast is safe — but keep it.

(e) Containment (“has-a”) boxes — composition is drawn as nesting, not as a line. A large steel-blue #4080B0 filled rectangle is the whole, labelled in large white text at its right edge (car, drone); a smaller brick-red #C05040 rounded rectangle sits inside it and is the part, labelled in white at its top with its methods listed beneath (engine / stop() / start()). (09a p6, p16)

Substitution is shown by stacking two such figures and joining them with a thick curved orange #F79646 arrow from the old configuration to the new (09a p16, “Hot-Swapping”).

Consistency: (e) holds twice in one deck and is the course’s only purpose-built composition picture. (a)–(d) are one or two pages each.

The large worked example

10a p13 — the only whole-system class diagram in the course — is drawn in a completely different style from the rest of 10a:

  • Single-compartment boxes, name only, pastel fills with matching darker strokes.
  • Sampled fills #D0E0F0 blue / #D0E0D0 green / #F0E0C0 orange, with strokes #6080B0 / #80B060 / #D09000. These are the draw.io / diagrams.net default shape colours, matched exactly — this figure was built in draw.io with stock styling, not drawn to match the deck.
  • Dashed lines with small open arrowheads for association/dependency (WTController → WTView, WTModel → Tank), solid lines with the usual filled triangle for inheritance.
  • Tiny 1 / N multiplicities at the line ends.
  • Green fill appears on Tank, Tile and Enemy — the three classes that have subclasses. This is my inference from one figure, and Battlefield (blue, no subclasses) is consistent with it while WTView (orange, alone) is not explained. Do not rely on it.

Reference and memory diagrams

The course does not draw its own reference diagrams. It uses Python Tutor.

pythontutor.com output is embedded as a screenshot in 07b p7, p12 and 07c p13, p14, and named as a live-demo cue five times in 02a (p22, p24, p25, p26, p27, captioned Python Tutor 1. through Python Tutor 5.).

The Python Tutor rendering, as it appears in those screenshots:

  • Two columns under bold headers Frames (left) and Objects (right).
  • A frame is a pale blue box with a bold title (Global frame) and one row per name; each row is name right-aligned against a value cell.
  • An object is a pale yellow box with a small red-brown type caption floating above it — Point class, Point instance, function.
  • An attribute inside an instance is a two-cell row: grey name cell, white value cell.
  • A reference is a curved blue-grey arrow from a frame slot to the object.
  • Aliasing is shown by two arrows converging on one object (07c p14), versus two arrows to two separate objects for equal-but-distinct values (07c p13).

Consistency: two decks, four screenshots, plus five named references in a third deck spanning week 2 to week 7. Treat Python Tutor as this course’s canonical memory picture.

Bit and memory notation

Established in 02a and legended explicitly on p4.

  • A bit is a square cell. Filled black = on/1. White with a black outline = off/0. 02a p4 draws the two side by side and labels them On and Off.
  • Held on 02a p6, p7, p8, p9, p10, p11, p12 — seven further pages.
  • A bit string is a horizontal row of contiguous squares, read left to right, with . . . after the last cell for continuation (02a p10, p11).
  • Memory is rows of words stacked vertically, each row prefixed in the left margin by its address as a small decimal number (02a p12: 381–388).
  • Enumerating all n-bit patterns stacks one row per pattern (02a p7, p8, p9).

Consistency: very strong within 02a. Never used again — no later deck draws a bit.

Data-structure and algorithm-trace diagrams

NoteThe one explicit figure-source statement in the course

12b p2: “Note: The diagrams from today’s lecture are taken from runestone.academy.”

This is the closest thing CSSE1001 has to a textbook lineage, and it governs every sorting and merge-tree figure in 12b (p4, p7, p10, p13, p14). Those figures are Runestone Academy’s, not the lecturer’s, which is why their visual language matches nothing else in the course.

List cells. A list is a horizontal row of adjacent square cells with a thin grey border and a soft drop shadow, one integer per cell in small sans-serif, centred. (12b p4, p7, p10, p13, p14)

Shading marks state. White = untouched; grey fills mark the cells the current step is acting on or the region already sorted. The exact meaning of each grey level is never legended — see Not established.

A trace runs top to bottom. Each row is one step; time advances downward. (12b p4, p7, p10)

Step captions sit to the right of each row, small black sans-serif, in the present tense of what just happened: 93 is largest, inserted 26, Exchange / No Exchange, 91 in place after first pass. (12b p4, p7, p10)

Movement arrows are thin black orthogonal arrows drawn above the row, running from source cell to destination cell (12b p4). A whole pass gets a long labelled arrow spanning the figure above everything else — First pass (12b p10).

Recursion trees (merge sort, 12b p13–p14) are drawn as binary trees of list-rows:

  • Merge Sort – Winding (p13): the full list at the top, splitting downward, arrows pointing down from a list to its two halves.
  • Merge Sort – Unwinding (p14): the singletons at the top, arrows pointing down into each merged result, ending in the sorted list at the bottom.

Both use downward arrows. The recursion direction is carried by the slide title and by which end of the tree holds the whole list — not by arrow direction. This is easy to get wrong.

Mathematical and logical notation

Truth tables (03b p6, p7). A 3×3 grid with visible black rules; the operator name sits in the top-left cell in cyan monospace (and, or); the header row and header column carry the operand values in black monospace; a double rule separates the headers from the body. The one semantically interesting result is coloured magenta — the single True for and (p6), the single False for or (p7).

Function signatures are given above the table, centred, mixing monospace names with maths: and : 𝔹 × 𝔹 → 𝔹. Also > : ℤ × ℤ → 𝔹 (03b p5) and P : ℕ → {True, False} (12a p11).

Blackboard bold for domains — 𝔹 booleans (03b p4, p5, p6, p7), ℤ integers (03b p5), ℕ naturals (12a p11, p13). 𝔹 = {True, False} is defined with the Python literals inside the set, in monospace (03b p4).

Python literals stay in monospace inside maths. True and False are never italicised into maths variables.

Implication and quantifiers use ⟹ and ∀: (P(0) and (P(n) ⟹ P(succ(n)))) ⟹ ∀m ∈ ℕ, P(m) (12a p11). Note and stays as the Python keyword in monospace even inside a mathematical statement.

Contradiction is ⇒⇐ (02a p20).

Displayed maths is centred on its own line, in magenta when it is the point being made (02a p20, 12a p11).

Arrow chains stand in for flow diagrams. Simple pipelines are written inline as text with → rather than drawn: state change → _check_invariants → valid (08b p8), parent → child → grandchild (10b p12), Task + TodoList → Model (domain) (11a p8). Consistency: three decks. This is why the course has so few real flow diagrams.

Geometric and proof figures

The chessboard-tiling figures for the induction proof (12a p12, p14, p15):

  • The construction is drawn in cyan solid lines.
  • The underlying reference grid is grey dashed.
  • The distinguished (uncovered) square is a filled magenta disc.
  • Dimensions are annotated with cyan extension lines outside the figure, labelled in black serif maths (2ⁿ, 2ⁿ⁺¹), placed below and to the right.

Consistency: three pages, one deck, entirely self-consistent.

The one flow diagram

07a p17 is the only control-flow diagram in the 726 pages. It shows try/except/else/finally:

  • Nodes are rounded rectangles with a hand-drawn, wobbly grey stroke (a sketch/xkcd style).
  • The node label is the bare Python keyword in monospace, coloured per keyword: try teal, except magenta, else blue, finally purple.
  • finally is drawn with a dashed sketchy border; the other three are solid.
  • Flow runs top to bottom, with curved grey arrows looping out to the left.
  • Edge captions are bold sans-serif, placed below the arrow they describe: Run the code under try, Execute the code under except when there is an exception, No exceptions? run the code under else after try, Always run this code.
  • Status glyphs sit outside the flow: a purple circled ✗ beside the try→except path, a green circled ✓ beside the try→else path, a blue circled i beside finally.
Warning

This is a single instance. It does not establish a general flowchart convention for the course — see Not established.

The LEGB diagram

07b p13 draws name resolution as a vertical cascade:

  • Four levels listed top to bottom, each with its initial letter bold — Local, Enclosing, Global, Built-in.
  • Between consecutive levels, a large red hook arrow with the small red caption If not found to its left.
  • The cascade terminates in bold red Error!.

Red marks the failure path. Single instance.

Naming and capitalisation

The three rules the course states in words, not just in examples:

Kind Rule Evidence
Variables, functions lowercase, words separated by underscores — descriptive_variable_name 03a p25
Classes CamelCaps — “That is ClassNamesAreLikeThis” 07c p7
Constants SNAKE_CASE_CAPS 07b p5

03a p24 states the course follows Google’s PEP, “a variant of PEP8”, with both linked as lavender rounded chips. 03a p26: lines must be strictly less than 80 characters.

These rules govern labels in diagrams too. UML boxes use CamelCaps class names (DeliveryRobot, WTController, DroneFlight) and snake_case members (_check_invariants(), has_solar_panels, battery_level) throughout 10a, 10b, 07c and 08a.

Do/don’t pairs. Compared alternatives go in a two-column table headed Yes and No in magenta italic, with a single rule under the headers and no other lines — good on the left, bad on the right (03a p25, p28). The variant form labels two separate ruled listings Not helpful / Helpful in magenta italic (03a p27). Inside dark-theme code screenshots the same judgement is made with an all-caps comment — # BAD! / # GOOD! (08b p7).

Figure sourcing and attribution

No textbook is cited as a figure source anywhere. A full-text search of all 25 decks and the course profile for textbook, figure-source and adaptation language returns only the four items below. The course profile prescribes no textbook at all.

Attribution Where Scope
Based on slides from Dr. Azadeh Ghari-Neiat Title page of 07a, 07b, 07c, 08a, 08b, 09a, 09b, 10a, 10b, 11a Slide lineage, not figure lineage
Based on slides from Dr. Azadeh Ghari-Neiat and Dr. Paul Vrbik 07b title page as above
Note: The diagrams from today's lecture are taken from runestone.academy. 12b p2 All sorting figures in 12b
Image source: www.freepik.com 09a p9 That slide’s stock art
Images are from WIRED 09b p2, p3 Those slides’ photos
Inspired by the example of MIT6.100L slide. 07c p10 The blueprint/house analogy — an idea, not a figure family

Placement. Credits are set in tiny centred or bottom-right roman type beneath the figure (09a p9, 07c p10) or in the bottom-right corner of the slide (09b p2, p3).

10b p9 refers to “the course notes” as the source of a code snippet — the course has its own written notes (delivered via Ed Lessons) which are not among these materials and may carry conventions this note cannot see.

Page furniture

  • Slide titles: dark blue #3030B0, serif, upper-left, sentence case with title-case content words. Optional Content: is used as a prefix for non-examinable material (10b p5).
  • Footer: n / N in tiny grey at the bottom-right. Unreliable — see How to read the citations.
  • Title slide: course code and title in blue, lecture number and name in magenta italic, lecturer, date, then the attribution line. (10a p1, 09a p1, 09b p1, 10b p1, 11a p1)
  • QR-code slides: a large centred QR code with the URL in small serif beneath, flanked by decorative 3D clip art, no title (07a p19, 07b p18, 09b p19).

Inconsistencies

Places where the course does the same thing more than one way. Both readings are recorded; a decision is needed before drawing.

1. Two entirely different UML idioms inside one deck

10a p4–p11 draws three-compartment black-outlined class boxes with magenta relationship lines, orthogonal routing and no fills. 10a p13 draws single-compartment pastel-filled draw.io boxes with dashed dependency arrows. Same deck, same lecture, same subject. 10b p19 adds a third variant: single-compartment boxes with navy #103040 outlines. Decide: compartments or not, fills or not, box outline colour.

2. Class boxes are drawn four incompatible ways before week 10

Three-compartment black box (10a p6); attributes-box-above-methods-box with the name outside and magenta outlines (07c p6); attributes-left/methods-right around a central black name box (08a p2); plain filled rectangle with name only (09b p2, p4). Decide which is canonical for pre-UML material.

3. Inheritance connectors: three styles

Orthogonal bracket with no arrowhead (09b p2, p3); straight blue lines each with its own arrowhead, overlapping at the parent (09b p4, p5, p6); orthogonal bracket with a filled triangular arrowhead (10a p4, p7–p11; 10b p19). Decide.

4. Hierarchy box colour: uniform vs. per-child

09b p2/p3 fill every box the same steel blue. 09b p4/p5/p6 make the root black and give each child its own colour. The two appear two pages apart. And 10a p13 uses a third scheme where colour may track “has subclasses”. Decide whether fill colour means anything at all.

5. Warning heading: red or purple

Red #F00000 in 12a p10 and 04b p14. Purple #7030A0 in 07b p6. Decide.

6. Two greens for the same role

Question / Exercise / Example / Task are #109050 in the LaTeX decks (02a p5, 03b p11) but #00B050 in the PowerPoint ones (10a p12, 11a p8). Same meaning, two hexes. Additionally 01a p25 sets Question in a magenta/crimson rather than either green (observed visually; my colour sample of that page missed the heading). Decide one green.

7. Boxed-token highlight colour is unfixed

Purple (07c p9, p16), magenta (07a p18), blue-and-purple keyed to two referents (09b p9). Decide.

8. Three code presentations

Ruled + line-numbered LaTeX listings (most decks); dark-theme screenshots of an IDE (09b p8–p13, p16; 10b p2, p4, p5; 08b p7); and plain unruled, unnumbered monospace (07a p16, p20). 09b switches between the first two within a single deck. Decide.

9. Summary styling

Purple block heading (02a p28, 07a p21, 07b p19); blue slide title (10a p14, 11a p14); magenta (09b p18). Decide.

10. Image credits are given inconsistently

09a p9 and 09b p2/p3 credit their stock photography. 01a p23–p29 (Ada Lovelace, Grace Hopper, the Jacquard loom, punch cards, the first computer bug), 07c p6/p10, 08a p2/p4 and 12a p4–p9 (the meme sequence) credit nothing. Decide a credit policy.

11. Bit-string reading order

02a p7–p9 enumerate n-bit patterns by toggling the leftmost cell fastest (off-off, on-off, off-on, on-on), which reads the leftmost cell as least significant. 02a p11 then interprets a word as 1·2³² + 1·2³¹ + … + 1·2⁰, reading the leftmost cell as most significant. If you draw a numbered bit string, decide which end is the high bit.

12. Exercise as heading vs. divider

A green block heading in 03b p11, 12b p5, 09b p17, 10a p12, 11a p8 — but a full magenta italic divider slide in 08b p11. Decide.

Not established by the source

Conventions a diagram in this course will plausibly need, that the materials simply do not settle. This is where the risk of invention lies.

No general flowchart convention. The only flow diagram in 726 pages is 07a p17’s sketch-style try/except figure. There is no established shape vocabulary (no decision diamond, no terminator, no process box), no arrow style, and no rule for labelling branches. If you need a flowchart, you are inventing one. Note that the course’s habit is to write flow as an inline → chain (08b p8, 10b p12, 11a p8) rather than draw it — consider doing that instead.

No MVC diagram. The entire MVC deck (11a, 14 pages) contains no architecture diagram. The Model/View/Controller relationship is given as a six-item numbered list (11a p6, p13) and a four-column table (11a p5). The only place the three appear as boxes is 10a p13, where they are three unremarkable draw.io rectangles among thirteen. There is no established shape, layout, arrow direction, or colour for an MVC diagram in this course.

No hand-drawn reference or memory diagram. The course never draws its own variable/object box-and-arrow picture — it screenshots Python Tutor (07b p7/p12, 07c p13/p14). If you need a reference diagram that Python Tutor cannot produce, there is no house style to follow.

No list or aliasing diagram. 04b (non-primitive data, 45 pages) teaches aliasing, copying and pass-by-reference entirely through REPL transcripts — mutating ys and observing xs change (p10, p12, p13). Not one box-and-arrow picture of a list. The idea of “two names, one list” is never drawn outside Python Tutor.

Grey-level semantics in the sorting traces are never legended. 12b p4, p7, p10 use at least three shades — white, light grey, darker grey — and no slide says which is “being compared”, which is “sorted”, and which is “just moved”. Since these figures are Runestone’s, the course has no stated rule to appeal to.

No stated meaning for fill colour in class boxes. 09b p5’s brick red, teal and orange appear decorative; 10a p13’s green may mark classes with subclasses but this is one figure and WTView’s orange contradicts any simple reading. There is no colour key anywhere.

No convention for showing a method body, call stack, or sequence of calls. Despite 12a (recursion, 47 pages) there is no call-tree or stack-frame diagram of the course’s own making — recursion is taught with memes (p4–p9), induction on chessboards (p12–p15) and code. No UML sequence diagram, activity diagram, state diagram or object diagram appears anywhere in the course.

No rule for typing method returns in UML. 10a p6 writes +info(): str; 10a p7–p11 write +info(). Both are the same method on the same class in the same deck.

No hex values are ever published. Every colour in this note was sampled from the rendered PDFs. The course states no palette, so a redrawn figure matching these hexes matches the slides by measurement, not by declaration.

Abstract classes have no notation. 10b p3–p5 teaches abstract base classes in prose and code only. UML’s italic-name convention for abstract classes is never used; Shape is never drawn.

Line weights, font sizes and box dimensions are never specified, and vary between the two slide families.

The eight unread decks. 00-welcome, 01b, 02b, 04a, 05a, 05b, 06a, 06b were not read as images. They contain no embedded raster images (except 00-welcome’s six photo pages) and are in the LaTeX family, so they are unlikely to hide a new idiom — but this note cannot rule it out.

The written course notes. 10b p9 cites “the course notes” as a source. Those notes are delivered through Ed Lessons and are not part of these materials. If they contain diagrams, they may establish conventions that contradict this note.

See also

Python Dunder (Magic) Methods

Dunder (“double underscore”) or magic methods are special methods, named __like_this__, that Python calls automatically to implement built-in behaviour for a type — instantiation, printing, equality, arithmetic operators, and more. You don’t call them directly; Python invokes them on your behalf when the corresponding syntax/built-in is used.

See 2025-09-16-dunder-methods for the lecture note, and python-classes-and-objects for classes generally.

Common dunder methods

Method Called by Purpose
__init__(self, ...) ClassName(...) Initializes a new instance. Returns None — it fills in an object that already exists rather than producing one.
__str__(self) print(obj), str(obj) User-friendly display string.
__repr__(self) the REPL, repr(obj) Unambiguous, developer-facing string — ideally a valid Python expression that recreates the object via eval().
__eq__(self, other) obj == other Custom equality (instead of identity).
__add__(self, other) obj + other Addition.
__sub__(self, other) obj - other Subtraction.
__neg__(self) -obj Unary negation.
__len__(self) len(obj) Length.

Every binary method takes the left operand as self and the right one as other.

__repr__ vs. __str__

  • __repr__ is for the programmer: unambiguous, meant for debugging/logging, ideally eval(repr(obj)) reconstructs an equal object. The round trip is obj → repr() → source text → eval() → a second object, whose repr matches the first’s.
  • __str__ is for the user: a friendly, readable string, used by print().
  • If only __repr__ is defined, print() falls back to it. If neither is defined, printing an object shows its default <... object at 0x...> representation.

A consequence that catches people out: at the interactive prompt, >>> obj and >>> print(obj) can produce completely different text from the same object, because they go through different methods.

Type-hinting a class inside its own body

Methods like __add__ want to say they return the class being defined, but the class object doesn’t exist yet while the body is executing:

from __future__ import annotations   # makes annotations lazy (strings)

class Fraction():
    def __add__(self, other) -> Fraction:   # legal because of the import
        ...

Without that import, -> Fraction is evaluated immediately and raises NameError; the alternative is to quote it, -> "Fraction".

Overloadable operators

Binary Method Unary Method Comparison Method
+ __add__ - __neg__ < __lt__
- __sub__ abs __abs__ <= __le__
* __mul__ ~ __invert__ == __eq__
** __pow__ != __ne__
// __floordiv__ > __gt__
/ __truediv__ >= __ge__

Operators can be defined in terms of each other rather than from scratch — Fraction.__sub__ is just return self + -other, i.e. __add__ composed with __neg__.

Instance variables vs. class variables

An instance variable (self.x = ...) belongs to one specific object — each instance has its own copy. A class variable (declared directly in the class body) is shared by all instances of the class, and can be accessed either via an instance (obj.class_var) or via the class itself (ClassName.class_var), without needing any instance at all.

class Clicker():
    _all_clicks = 0   # class variable -- shared by every instance

    def __init__(self) -> None:
        self._clicks = 0   # instance variable -- unique per object

    def click(self) -> None:
        self._clicks += 1
        Clicker._all_clicks += 1

Why Clicker._all_clicks += 1 and not self._all_clicks += 1. self._all_clicks += 1 expands to self._all_clicks = self._all_clicks + 1. The read on the right-hand side finds the class attribute (attribute lookup falls back to the class when the instance has no such name), but the assignment on the left always writes an instance attribute. So the first click on each object creates a private _all_clicks on that object that shadows the shared one forever, and the class-level total stays at 0. Naming the class explicitly is what makes the update land on the shared cell.

Reading through an instance is fine — c._all_clicks returns the class’s value, which is why the transcript in 2025-09-16-dunder-methods shows (6, 6, 6). It is only assignment through an instance that breaks the sharing.

Worked example: Vector2D

A fuller worked example combining several dunder methods together. The length is Euclidean: for (2, 3) it is sqrt(13), 3.605551275463989.

import math

class Vector2D():
    def __init__(self, x, y):
        self.x = x
        self.y = y

    def length(self):
        return math.sqrt(self.x**2 + self.y**2)

    def __repr__(self):
        return f"Vector2D(x={self.x}, y={self.y})"

    def __str__(self):
        return f"2D Vector: ({self.x}, {self.y}) --- length: {self.length()}"

    def __eq__(self, other):
        return isinstance(other, Vector2D) and self.x == other.x and self.y == other.y

    def __add__(self, other):
        if not isinstance(other, Vector2D):
            return NotImplemented
        return Vector2D(self.x + other.x, self.y + other.y)

    def __len__(self):
        return 2
>>> u = Vector2D(2, 3)
>>> v = Vector2D(4, 5)
>>> print(u + v)
2D Vector: (6, 8) --- length: 10.0
>>> print(u)          # calls __str__
2D Vector: (2, 3) --- length: 3.605551275463989
>>> repr(u)            # calls __repr__
'Vector2D(x=2, y=3)'
>>> u == v              # calls __eq__
False
>>> len(u)               # calls __len__
2

print(u + v) uses two magic methods in one expression: __add__ builds the new vector, then print displays it through __str__.

Returning NotImplemented (rather than raising or returning False) from a method like __add__ is the standard way to signal “I don’t know how to combine these two types” — it lets Python fall back to the other object’s reflected method, or raise a clean TypeError if nothing handles it.

Python Inheritance

Inheritance lets a class (the subclass/child class) reuse the attributes and methods of another class (the superclass/parent class), while adding new behaviour or overriding existing behaviour. It models an “is-a” relationship (a DeliveryRobot is a Robot) — contrast with python-composition’s “has-a” relationship.

Syntax

class Parent():
    # Parent class' implementation

# inherit from the Parent class
class Child(Parent):
    # Child class' implementation

Child inherits everything Parent defines, without naming any of it.

Figure 8: The class Child(Parent): line, annotated: the name being defined comes first, the name being inherited from goes in the parentheses. The box round each name, the arrow leading from it, and the matching word in the sentence beneath are all one colour: blue tracks the child and purple the parent throughout.

A subclass automatically gets all of its parent’s attributes and methods. It can:

  • Add new methods/attributes that only it has.
  • Override an inherited method by redefining it with the same name.
  • Extend an inherited method using super(), rather than fully replacing it.

Those three, plus plain inheritance, are the four things a subclass can do with any given member:

The subclass… …does this Effect on the parent’s version
says nothing about the member inherits it used unchanged
declares a member the parent doesn’t have adds it none — the parent has no such member
declares a member with the same name overrides it shadowed; never runs for this class
declares it and calls super() inside extends it runs, plus whatever the subclass adds

A subclass that declares no __init__ of its own uses the parent’s, so constructing it takes the parent’s arguments. Declaring one replaces the parent’s — which is why an extending __init__ almost always opens with super().__init__(...).

super()

super().method(...) calls the parent class’ version of a method — most commonly used inside an overridden __init__ to reuse the parent’s initialization logic before adding subclass-specific setup:

class DeliveryRobot(Robot):
    def __init__(self, name: str, batt_level: int, load_capacity: int):
        super().__init__(name, batt_level)   # reuse Robot's __init__
        self.load_capacity = load_capacity

Terminology cheat-sheet

Given class Student(Person):

Term Refers to
subclass / child class Student
superclass / parent class Person
“Student inherits from / extends Person” the relationship between them

Polymorphism

Polymorphism (“many forms”) describes an interface that works across different underlying types. Built-ins like len() are polymorphic (works on strings, lists, dicts, …). Classes that share a method name (whether via a common superclass or just by convention) are also polymorphic: the same call, e.g. r.charge(), produces different behaviour depending on which actual class r is an instance of.

Which method actually runs is decided by the object, not by the calling code, and is resolved by walking up the hierarchy until the name is found: object's own class → parent → grandparent → .... A subclass that overrides the name stops that walk at itself; one that doesn’t lets it continue to the parent. Nothing in the caller has to know or ask which case it is — that is what makes a loop over a mixed list of subclasses work, and why adding another subclass later needs no change to the loop.

When to use inheritance

Only when there’s a genuine “is-a” relationship between the two classes. If the relationship is really “has-a” (one object contains or uses another), prefer python-composition instead. See 2025-09-23-inheritance for the worked Robot hierarchy and 2025-09-23-composition for the DroneFlight counter-example.

Abstract base classes

An abstract base class doesn’t provide concrete implementations for some/all of its methods — it just defines the interface that every concrete subclass must implement. You’re not meant to instantiate the abstract class directly.

The simplest (unenforced) version just raises an error from each method that subclasses must override:

class Shape:
    def area(self) -> float:
        raise NotImplementedError("Subclasses must implement area()")

This only fails when the unimplemented method is actually called — Shape() itself still succeeds. The standard-library abc module enforces this properly, raising TypeError at the point of instantiation:

from abc import ABC, abstractmethod

class Shape(ABC):
    @abstractmethod
    def area(self) -> float:
        ...

    # concrete helpers are still allowed alongside abstract methods
    def describe(self) -> str:
        return f"{self.__class__.__name__}"

With ABC, Shape() raises immediately: TypeError: Can't instantiate abstract class Shape with abstract methods area.

Method Resolution Order (MRO)

When a class inherits from multiple parents (or a chain of parents) that define the same method/attribute name, Python needs a deterministic rule for which one wins. That rule is the Method Resolution Order (MRO) — the order Python searches through classes to resolve a name on an object. It’s stored on the class as cls.__mro__ (or cls.mro()).

Python’s inheritance models

  • Single inheritance: class B(A): — one parent.
  • Multilevel inheritance: class C(B): (where B itself inherits from A) — a linear chain; the MRO just follows the chain upward.
  • Hierarchical inheritance: multiple children (B, D, …) inherit from the same parent A.
  • Multiple inheritance: class E(B, D): — a class inherits from more than one parent directly.

The diamond problem and C3 linearisation

If E(B, D) and both B and D inherit from A, which version of A’s methods should E use? Python resolves this with C3 linearisation:

  • Child classes are checked before parents.
  • Parents are checked in the order they’re listed in the class definition.
  • If a class would appear more than once, only its last occurrence is kept.
>>> class E(B, D): pass
>>> [cls.__name__ for cls in E.__mro__]
['E', 'B', 'D', 'A', 'object']

Each attribute/method name is resolved independently by walking this list and taking the first class that defines it — so two different method calls on the same object can effectively “come from” two different classes in the hierarchy.

super() follows the MRO

super() doesn’t call the immediate parent named in the class statement — it calls the next class after the current one in the instance’s actual MRO. This is what makes cooperative multiple inheritance work: as long as every class in the chain calls super(), a single call can ripple through every class in the MRO exactly once, in order.

class A:
    def ping(self): print("A")
class B(A):
    def ping(self): print("B"); super().ping()
class C(A):
    def ping(self): print("C"); super().ping()
class D(B, C):
    def ping(self): print("D"); super().ping()
>>> D().ping()
D
B
C
A

If any class in the chain omits its super() call, the chain simply stops there for that call — the MRO itself doesn’t change (it’s purely a function of the class hierarchy), but fewer methods actually get executed.

UML Class Diagrams

UML (Unified Modelling Language) diagrams are the standard, language-agnostic way of visually describing the classes in a system and the relationships between them — useful for planning a design before writing code, and for communicating that design to others.

This note is the notation reference. The lecture note is 2025-10-07-uml; for how CSSE1001 draws diagrams generally, see csse1001-diagram-notation.

Class boxes

A class box is a rectangle in three compartments, separated by full-width horizontal rules:

ClassName
-----------------------
attributes
-----------------------
methods()

Each attribute/method is prefixed with a visibility marker:

Symbol Visibility
- private
+ public
# protected

CSSE1001 conventions:

  • Attributes are typed Python-style: name: type, e.g. #age: int, -nationality: str, -pets: [].
  • An empty compartment is kept, not collapsed. A class with no attributes of its own is still drawn with a blank attributes band.
  • Names follow the course’s Python naming rules — CamelCaps for class names, snake_case for members (see python-pep8-style-guide).
  • Single-compartment, name-only boxes are acceptable when only the shape of a hierarchy is being shown.
  • Method return types are optional: the same method can be written +info(): str or +info(). Do not read meaning into the difference.

Relationship types

Figure 9: The relationship symbols as CSSE1001 draws them. The inheritance arrowhead is filled, which is the course’s deviation from textbook UML, and the diamond always sits at the whole end. The dependency head is filled as well. Child, Parent, Whole and Part are generic stand-ins for concrete classes.

Relationship Line style Meaning
Inheritance solid line, filled triangular arrowhead pointing at the parent “is-a” — subclass inherits from superclass
Association plain solid line, no head, optional verb label at one end one class uses/references another, without ownership
Aggregation solid line, hollow (open) diamond at the “whole” end weak “has-a” — the part can exist independently of the whole
Composition solid line, filled (solid) diamond at the “whole” end strong “has-a” — the part cannot exist independently of the whole
Dependency dashed line, small filled arrowhead one class depends on another
WarningFilled, not hollow

Standard UML draws generalisation with a hollow triangle. CSSE1001 draws it solid filled on every inheritance arrow. Follow the course, not the textbook. See csse1001-diagram-notation.

NoteThe dependency head is solid as well

The dashed dependency arrow ends in a filled head in CSSE1001, not an open one. The head takes two forms: a filled concave-backed “classic” arrow, or a plain straight-backed filled triangle. Both are solid, and both differ in shape from the inheritance head.

Layout

  • Routing is orthogonal. Relationship lines use right-angle elbows, never diagonals.
  • A parent with several children gets one bus: a single vertical stem from the parent down to a horizontal line, with a vertical drop to each child — not one arrow per child.
  • Parent above, children in a row beneath. A grandchild hangs directly below its own parent with its own arrow.
  • Non-hierarchy classes usually sit to the side, at the same height as the class they attach to (Vet, Heart and Owner in the examples in 2025-10-07-uml). The exception is Milk, which hangs directly below Cat with the association line running down Cat’s left edge.

Multiplicity

Multiplicity annotations on association/aggregation/composition lines describe how many objects on each end participate in the relationship. They are placed above the line, next to the end they qualify:

Notation Meaning
0..1 zero to one
n an exact number
0..* zero to many
1..* one to many
m..n a specific range

Why use UML?

  • Plan a class hierarchy/object graph before writing any code.
  • Communicate a design to teammates without needing to read source code.
  • Document the intended structure and relationships for future maintenance.
  • Class diagrams are the most commonly used UML diagram type in object-oriented design, but UML also includes other diagram types (e.g. sequence diagrams, use-case diagrams) not covered in this course.