From the course: Learning SOLID Programming Principles
Unlock the full course today
Join today to access over 24,500 courses taught by industry experts.
More OCP extension techniques - Python Tutorial
From the course: Learning SOLID Programming Principles
More OCP extension techniques
- [Instructor] The Open-Closed Principle relies on keeping a class open for extension, but closed to modification. Python offers us a variety of ways to extend a class. In the previous section, I talked about the two most common techniques for extending a class, inheritance and composition. In this section, I'll look at three the other ways to extend a class. Decoration rewrites a class. This works well when introducing a cross-cutting concern like security or application-wide logging. Mixins and multiple inheritance are ways to do class composition. And finally, functional composition follows from the ideas underlying functional programming. This design relies on nested function calls instead of sequences of object methods. A Python decorator is a function which transforms an original class definition into a modified class definition. It's a way of rewriting a class to extend it. It works best with things like audit…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.