Join Steven Lott for an in-depth discussion in this video Extend alternatives, part of S.O.L.I.D. Programming Principles.
- View Offline
- [Voiceover] The interface segregation principle…suggests that a class have the smallest possible interface.…Python's more flexible approach,…sometimes called duck typing,…opens up some useful design alternatives.…Duck typing gets its name from this quote.…"When I see a bird that walks like a duck…"and swims like a duck and quacks like a duck,…"I call that bird a duck."…This summarizes Python's "effectively the same type" rules.…
If two objects have the same methods and attributes,…then for all practical purposes in Python,…they may as well be members of the same class.…Python doesn't rely on the actual type…but the presence of the methods and attributes.…This means that it isn't helpful to be strict…about applying interface segregation…in the case of wrapping generic, built-in types.…It's much simpler to extend a built-in type…and rely on duck typing to limit the effects of change.…
This implementation of deck, the DeckX implementation,…is another name for the built-in list class.…Introducing a new name allows a different implementation…
To incorporate SOLID into your own development workflow, Steven Lott has prepared a series of lessons that break down the principles one by one, with real-world examples. Learn how to use these principles in the design process, and to test the strength of your code along the way. Steven uses Python to demonstrate the concepts, but they're useful for any object-oriented programming language.
- An overview of SOLID principles
- Segregating code into client-specific modules
- Testing code by substituting subtypes for base classes
- Keeping software open for extension but closed to modification
- Eliminating dependencies on details
- Assigning one responsibility to each class
- Using SOLID principles in the design process