Menu

Sign in to track your progress and unlock all features.

Theme style

Log in

Full lesson preview

Override Methods While Preserving Parent Behavior

Override methods in subclasses but call super() so the parent's behavior is preserved and extended.

Python practice17 minInheritance & PolymorphismIntermediateLast updated April 8, 2026

Problem statement

Implement a base Notifier class that records notifications in a list. Then implement LoudNotifier (which uppercases messages) and CountingNotifier (which counts notifications). Both should preserve the base Notifier's behavior by calling super(). Finally provide a CombinedNotifier that composes both behaviors via multiple inheritance. Write run_sequence(kind, messages) to create the chosen notifier, send each message, and return the notifier's log and count (0 if count doesn't exist).

Task

Create subclasses that override notify() while still using the base class' logging behavior by calling super(). Demonstrate combining behaviors using multiple inheritance.

Examples

Use LoudNotifier

Input

run_sequence('loud', ['hi'])

Output

(['Notified: HI'], 0)

LoudNotifier uppercases messages then uses the base Notifier to append the message to the log. Counting is absent, so count is 0.

Input format

Call run_sequence(kind, messages). kind is one of 'base', 'loud', 'count', 'combined'. messages is a list of strings.

Output format

Return a tuple: (log_list, count). count should be 0 if the notifier doesn't track count.

Constraints

Notifier.notify must append strings in the exact format 'Notified: <message>'. Subclasses must call super().notify(...) to preserve base behavior.

Samples

Sample 1

Input

run_sequence('count', ['a','b'])

Output

(['Notified: a', 'Notified: b'], 2)

CountingNotifier increases count for each notify while still appending the base log entries.