Object Oriented Theory with Python

A practical two day course on the object oriented features of Python. Perfect for programmers with some experience of Python looking to use objects and classes and to understand them. An excellent course for data scientists, devops engineers and those self taught with Python looking to move beyond scripting into programming.

The references and assignment section fills in gaps on the low level details of Python whilst the course covers the full object model. Learn how all Python object works, Python objects inside and out. The course is hands on with exercises for all the topics. Principles of API design, objects for data abstraction, and best practises are discussed throughout the course.

This course is taught by Michael Foord. Michael has been teaching Python for over a decade and has over twenty years industry experience as an application developer. Michael is a Python core developer and the creator of unittest.mock in the Python standard library, and is the author of The Absolute Minimum Every Python Web Application Developer Must Know About Security.

Fundamentals: Classes and methods

  • Computer architecture and programming languages
  • Python as a high-level, object-oriented language
  • Objects as abstractions, for thinking
  • The class statement
  • The explicit self
  • The initialiser method __init__
  • Bound methods
  • Attributes and the built-in attribute access functions
  • References and assignment (how Python works)
  • Mutable objects (and call by object)
  • Object copying

Object Oriented Features

  • Class attributes
  • Class methods
  • Properties
  • Private attributes
  • Single inheritance
  • Inheritance to extend and modify the parent
  • The use of super
  • Cooperative multiple inheritance
  • Mixin Classes
  • Attribute lookup and the method resolution order
  • The type system: isinstance and issubclass

Inside Python Objects

  • The instance dictionary
  • Slots
  • Class dictionaries
  • The descriptor protocol

Python Protocols

  • Magic methods and Python protocols
  • Operator overloading
  • The string representation protocol
  • The container protocols
  • Implementing custom containers
  • Inheriting from collections.abc.MutableSequence

Alternative Approaches

  • namedtuples
  • dataclasses
  • type as a class factory

Object oriented theory:

  • History of Object Oriented Programming
  • The pillars of OOP
  • Abstraction
  • Inheritance
  • Encapsulation
  • Polymorphism
  • Object oriented design principles
  • Design patterns
  • The Liskov Substitution Principle
  • Composition versus inheritance

Optional advanced section (third day):

  1. Advanced OOP Concepts

    • Interfaces and API design
    • Abstract base classes and protocols
    • Type hints and static typing with mypy
    • Class decorators
    • Decoration via inheritance with __init_sublass__
    • Metaclasses
    • Context managers and the with statement
    • Weak references and destructors
    • The descriptor protocol
  2. OOP Design Principles

    • SOLID principles
    • Law of Demeter
    • Liskov Substitution Principle
    • Composition vs inheritance
    • Domain Driven Design
    • Test Driven Development
    • Stop writing classes
    • The hexagon pattern (microservices)
    • The C4 Model for system architecture