>

Thursday, 17 December 2015

Single Responsibility Principle

“Every object should have a single responsibility and that responsibility should be entirely encapsulated by the class”
“Classes should have one responsibility- one reason to change”
Example:
Consider a module that compiles and prints a report. Such a module can be changed for two reasons. First, the content of the report can change. Second, the format of the report can change. These two things change for very different causes; one substantive, and one cosmetic. The single responsibility principle says that these two aspects of the problem are really two separate responsibilities, and should therefore be in separate classes or modules. It would be a bad design to couple two things that change for different reasons at different times.
Advantages:
1.Reuse
2.clarity
3.naming
4.Readability

0 comments:

Post a comment