Modelling and persistence
What is object-oriented design?
On this page
Design assigns the responsibilities uncovered during analysis to collaborating software components. A Loan can determine whether it is open, while a Calendar owns business-day calculations. Rehearse a return on a holiday and see which component has the knowledge to make each decision.
Worked example
Pythonfrom datetime import date, timedelta
class WeekdayCalendar:
def next_open(self, day):
while day.weekday() >= 5:
day += timedelta(days=1)
return day
class Loan:
def __init__(self, calendar):
self.calendar = calendar
def credited_return(self, day):
return self.calendar.next_open(day)
assert Loan(WeekdayCalendar()).credited_return(date(2026, 6, 6)) == date(2026, 6, 8)Explore class relationships in the OOP Playground