课程: Programming Foundations: Design Patterns
今天就学习课程吧!
今天就开通帐号,24,100 门业界名师课程任您挑!
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.…
随堂练习,边学边练
下载课堂讲义。学练结合,紧跟进度,轻松巩固知识。
内容
-
-
-
-
-
-
-
-
(已锁定)
Encapsulating iteration1 分钟 44 秒
-
(已锁定)
Understanding the Iterator pattern2 分钟 28 秒
-
(已锁定)
Using the Iterator pattern3 分钟 36 秒
-
(已锁定)
Using built-in iterators1 分钟 19 秒
-
(已锁定)
The single responsibility principle1 分钟 20 秒
-
(已锁定)
The iterator pattern as language feature1 分钟 30 秒
-
(已锁定)
Challenge: The Iterator pattern57 秒
-
(已锁定)
Solution: The Iterator pattern36 秒
-
(已锁定)
-
-