Loading...
Procedural and object-oriented designs organise responsibility differently. Choose a structure that exposes meaningful tasks and keeps data valid through clear interfaces.
What you'll be able to do
A procedural design organises work into routines that perform well-defined tasks. A hierarchy chart shows which broader tasks are decomposed into smaller tasks, such as load orders, calculate totals and produce a report. It is a structural view, not a substitute for the detailed order and decisions inside each algorithm.
Cohesive routines do one related job; loose coupling means they communicate through clear interfaces rather than manipulating each other’s internals. A shared calculation belongs in a reusable routine, making it easier to correct one implementation and test it independently.
A class defines the attributes and methods common to its objects. Instantiation creates an individual object, usually initialised by a constructor. Two account objects can follow the same class definition while holding different balances; the class is not itself one particular customer’s account.
A reference identifies the created object. In Python, __init__ initialises an instance after its creation, and self identifies the instance within ordinary methods. Use the constructor to establish valid starting state rather than relying on callers to remember a sequence of unrelated assignments.
Encapsulation groups data with the operations that maintain it and limits inappropriate access to representation details. A balance invariant might require non-negative values; deposit and withdraw methods can enforce that rule. Merely placing fields inside a class does not automatically make every operation safe.
UML access markers are + public, - private and # protected. Python’s underscore conventions are not identical to enforced Java or C# access modifiers: a leading underscore signals non-public use. Explain the intended interface and language mechanism separately, rather than claiming a convention creates absolute secrecy.
class Counter:
def __init__(self):
self._value = 0
def increment(self):
self._value += 1
def value(self):
return self._value
first = Counter()
second = Counter()
first.increment()
print(first.value(), second.value())Scroll horizontally to see the full code or table.Attempt the task before opening its worked response. Record each change of state, explain the rule used, and check the result against the original requirements. Code examples labelled Python 3 use that language’s conventions; pseudocode states its own assumptions.
Common mistakes to avoid
Key takeaways
Test yourself
Answer a few questions, then review anything you missed.
Start with the quiz above to check the key ideas. You can also choose another topic from the practice library.