From the course: Learning SOLID Programming Principles

Unlock the full course today

Join today to access over 24,400 courses taught by industry experts.

Collections of samples

Collections of samples

- [Instructor] We need to create a class to hold a collection of sample instances. And while the wrap versus subclass decision is something we always confront, it's particularly important in Python where we have so many built-in collection types. We can always wrap an existing collection. This is sometimes called design by composition because we're composing a new class from one or more existing classes. It fits well with interface segregation because we can define the minimal interface. In Python, it's easy to extend an existing collection by defining a new subclass. The design pattern books include a number of collaboration patterns that depend on how much of the underlying class is exposed through a wrapper. First, let's see what's at stake. Then we can look more closely at what wrapping involves. I need a subclass to hold a collection of samples. This can seem like a fussy bit of overengineering. A list of sample…

Contents