From the course: Programming Foundations: Design Patterns
Unlock the full course today
Join today to access over 24,000 courses taught by industry experts.
The single responsibility principle
From the course: Programming Foundations: Design Patterns
The single responsibility principle
- [Narrator] Let's think about responsibility for a minute. One thing to remember about giving responsibilities to a class, is that for every additional responsibility, a class has another reason it might have to change in the future. So by giving a class multiple responsibilities we give the class more than one reason it might have to change. And we know we want to minimize change where we can. This brings us to another design principle. The Single Responsibility Principle. Which says that a class should have only one reason to change. Adhering to this principle minimizes the chances that a class is going to need to change in the future. Now let's think about collections and iterators. If we allow a class to handle both the responsibilities of managing a collection, and managing the iteration, then we have two areas of potential change. That's why we separate the iteration responsibility into its own class.…
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.
Contents
-
-
-
-
-
-
-
-
(Locked)
Encapsulating iteration1m 44s
-
(Locked)
Understanding the Iterator pattern2m 28s
-
(Locked)
Using the Iterator pattern3m 36s
-
(Locked)
Using built-in iterators1m 19s
-
(Locked)
The single responsibility principle1m 20s
-
(Locked)
The iterator pattern as language feature1m 30s
-
(Locked)
Challenge: The Iterator pattern57s
-
(Locked)
Solution: The Iterator pattern36s
-
(Locked)
-
-