Saturday, September 14, 2013

Single Responsibility Principle


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.
http://stackoverflow.com/questions/3498200/organising-classes-and-modules-in-python

No comments:

Post a Comment