The rational behind the exact example that you gave is that if each class has a save method, then if you later change how you are saving data (from say filesystem to database or remote XML file) then you have to change every class. If each class implements an interface to yield that data that it wants saved, then you can write one function to save instances of every class and only change that function once. This is known as the Single Responsibility Principle: Each class should have only one reason to change. |
Showing posts with label Single Responsibility Principle. Show all posts
Showing posts with label Single Responsibility Principle. Show all posts
Saturday, September 14, 2013
Single Responsibility Principle
Subscribe to:
Posts (Atom)