Python OOP Secrets: Class Methods, Static Methods & Composition

Published: 14 November 2025
on channel: Sumantra Codes
23
2

📝 DESCRIPTION: Have you ever wanted to create your Python objects in more than one way , or had a helper function that doesn't use self? What if you could build powerful objects like Legos instead of relying on inheritance? In this video, you'll master Python's Class Methods, Static Methods, and the powerful concept of Composition to seriously improve how you write code.

This is Episode 4 of our Object-Oriented Programming in Python series. We'll start with @classmethod, showing you how to create alternative constructors (like a Person.fromString factory) that work on the class (cls) itself. Then, we'll cover @staticmethod and explain why it's the perfect tool for helper functions (like a Calculator.multiply function) that don't need self or cls. Finally, we dive deep into Composition, the "has-a" relationship (like a Car has an Engine) , and explain why you should often "favor composition over inheritance" for more flexible, reusable, and simple designs.

If this video helped you understand these ideas, please hit the like button and share this video with a friend who is learning Python. Most importantly, hit that subscribe button and ring the bell so you don't miss Episode 5! Thanks for watching Sumantra codes!

🕒 Video Chapters
00:50 - Topic 1: What is a Class Method?
01:25 - Example: Building a Person Class
01:51 - Code: Creating fromString with @classmethod
03:05 - Why Use Class Methods? (Alternative Constructors)
03:41 - Demo: Using the fromString Class Method
05:04 - Topic 2: What is a Static Method?
05:30 - Example: Building a Calculator Class
06:18 - Code: Creating multiply with @staticmethod
06:52 - Demo: Using Static Methods (No Instance Needed)
08:46 - Topic 3: The "Has-A" Relationship (Composition)
09:33 - Example: A Car HAS AN Engine
10:27 - Code: The "Magic Line" of Composition
11:03 - Demo: Building and Starting the Car
11:51 - Why Favor Composition Over Inheritance?


On this page of the site you can watch the video online Python OOP Secrets: Class Methods, Static Methods & Composition with a duration of hours minute second in good quality, which was uploaded by the user Sumantra Codes 14 November 2025, share the link with friends and acquaintances, this video has already been watched 23 times on youtube and it was liked by 2 viewers. Enjoy your viewing!