Module 10: Object-Oriented Programming
Intermediate 19 chapters
117. Introduction to OOP
Meet object-oriented programming: what objects, classes and attributes are, why they help organise code, and how to make a first class and objects.
118. Classes and Objects
Learn what a class is, how to create objects from it, and how objects keep their own data and behaviour. You will build small classes and use them step by step.
119. Constructors
Learn how the __init__ constructor sets up a new object, how to use parameters and default values, and how to avoid common constructor mistakes.
120. self Keyword
Understand what self means inside a class, how Python passes it automatically, and how to use it to read attributes, call other methods and return the object for chaining.
121. Instance Variables
Learn how instance variables store data that belongs to each object, how to create, read, change and delete them, and how they differ from local variables.
122. Class Variables
Learn what class variables are, how they are shared by all objects of a class, how they differ from instance variables, and the common traps with mutable values and shadowing.
123. Instance Methods
Learn how to write instance methods, how `self` connects a method to its object, and how methods read, change and return object data.
124. Class Methods
Learn how the `@classmethod` decorator works, what `cls` means, and how to use class methods as alternative constructors and to manage class-level data.
125. Static Methods
Learn what static methods are, how @staticmethod works, and when to use a static method instead of an instance method, a class method or a plain function.
126. Inheritance
Understand inheritance in Python: how a child class reuses a parent class, how to override methods, call super() and check relationships with isinstance and issubclass.
127. Multiple Inheritance
Learn how a class can inherit from more than one parent, how Python decides the lookup order with the MRO, how the diamond problem is solved and how mixins are used.
128. Multilevel Inheritance
Learn multilevel inheritance, where a class inherits from a child of another class, forming a chain such as grandparent, parent and child, and see how attributes, methods and super() work along the chain.
129. Method Overriding
Learn how a child class can replace or extend a method it inherits from a parent class, and how super() lets you reuse the parent's version.
130. Polymorphism
Understand polymorphism, where one interface works with many kinds of objects, through method overriding, duck typing and operator behaviour.
131. Encapsulation
Learn how encapsulation bundles data with methods and protects it using naming conventions, name mangling, properties, getters and setters.
132. Abstraction
Learn abstraction: hiding complex details behind simple interfaces, and using the abc module with abstract classes and abstract methods to force subclasses to follow a contract.
133. Properties
Learn how the @property decorator turns methods into attributes, adds validation with setters, creates computed values, and keeps your class interface clean.
134. Magic Methods
Discover magic (dunder) methods such as __init__, __str__, __repr__, __len__, __getitem__, __contains__ and __call__, and see how they let your own classes behave like built-in types.
135. Operator Overloading
Learn how to give your classes their own meaning for operators such as +, -, *, ==, < and unary minus by defining methods like __add__, __eq__ and __lt__.