Join Steven Lott for an in-depth discussion in this video High cohesion and indirection, part of S.O.L.I.D. Programming Principles.
- View Offline
- [Voiceover] There are a number of principles…for determining what counts as responsibility.…Previously I talked about the controller…of a use case or a story…and the creator of complex objects.…Here I'll talk about two more concepts,…using high cohesion as a reason…for combining objects, attributes, or methods,…or using indirection that is a bridge or a link…that separates objects.…The idea of high cohesion is a way…to look at combining features.…
It may be more cohesive to make a single class,…which is responsible for closely related features.…For example, the two methods that return…the hard and soft point values…for Blackjack cards seem cohesive.…They seem to belong with each other…and other features of a card.…They're not related to shuffling or dealing.…In this case, some highly cohesive features are combined…into a single responsibility.…While it's often clear that some elements…of a class are cohesive,…a poor choice of abstractions is what can lead to problems.…
For example, assuming that house rules for Blackjack…
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