![]() This is somewhat out of the norm for object oriented design, early object oriented design principles had as grouping together functions that operated on the same data structures so that the methods of a class would all manipulate the same variables of that class, but if those methods change for different reasons then they really belong in separate classes. So the Responsibility Principle simply says, "Find one reason to change and take everything else out of the class." So that you separate the things that change for different reasons, you group together the things to change for the same reasons. That means that this one class has three different reasons to change and there are probably many other classes that depend upon it and so as it changes those depending classes also suffer through change, they'll be effective or impacted by those changes. The save function will change if the DBA's decide that we needto change the database's schema. The report generator will change if the people who consume the reports want the format of the reports to change. The payroll, the calculate pay will change if the accountants decides on a new way of calculating pay. So for example, take a payroll application, if there's an employee class in that payroll application, you could imagine that it might have methods for calculate pay or perhaps another method for print a report, perhaps another method in the employee object for save me to the database, and what's unfortunate about these three methods existing in the same class is that they have all three completely different reasons to change. Single Responsibility Principle, what does it mean? It means that a software module should have one reason to change, then that's what I call a responsibility, a reason to change. Uncle Bob describes it as there should ONLY be a single person/Actor responsible for the change. (from SOLID Principles with Uncle Bob - Robert C.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |