dennis-fedco Posted March 20, 2014 Share Posted March 20, 2014 I am refactoring a class that has multiple responsibilities. After reading Single_responsibility_principle, I am still not sure, how to factor out the class into its aspects.The methods of the class are (summarized): class constructor Calculate {General, A, B} Convert {General, A, B} Load {General, C, D} Save {General, C, D} By General I mean i.e. load() function that can load A or B or both depending on the circumstances, and by A or B I mean more specific loadA(), or loadB().My specific questions in regards to SRP is: Do `load()` and `save()` belong to different classes, because they can in theory change at different times for different reasons, or can/should I put them into the same class, because loading/saving can be considered as "database operations" and if one changes so *may* the other, i.e. adding a new attribute to whatever is being saved/loaded? How do I organize the classes anyway? i.e. something like this? class CalculateGeneral() {}; class CalculateA() extends CalculateGeneral {}; class CalculateB() extends CalculateGeneral {}; class ConvertGeneral() {}; class ConvertA() extends ConvertGeneral {}; class ConvertB() extends ConvertGeneral {}; class LoadSaveGeneral() {}; class LoadC() extends LoadSaveGeneral{}; class LoadD() extends LoadSaveGeneral{}; Woah that's 9 classes out of 1 that it is now.. Quote Link to comment https://forums.phpfreaks.com/topic/287131-how-to-refactor-class-with-srpsolid-principles-in-mind/ Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.