As the SRP says, the way to achieve this principle is divide all into smaller. And what you have just made small, make more smaller. As consequence we got more files and my question is about it, how organize all this new classes that are generated to keep our dirs clean, as the code.
For example. I'm developing an Android app on which I have a functionality about read a rss feed. It is invoked from different screens. It's obvious that it is a responsibility but to achieve that, I have my sub responsibilities.
To read a RSS Channel I have to...:
- Download XML file from URL.
- Parse the XML file downloaded getting the channel details and all feed items.
So, I will have
RSSChannelReader.java whose public method, something like
read() will invoke
RSSDocumentParser.java. As SOLID principles suggest interface segregation, I will use the interfaces
IRSSDocumentParser.java to operate.
RSSDocumentParser.java will use
ChannelRSSFeedItem.java that works as
vo for general channel description and feed items values.
So, I will have all this new classes:
My app dir structure is:
- Activities/: Contains the app screens.
Then, where do I put all these new files? I supposed to put
business/RSSChannelReader. There is some problem if I mix the interfaces files with their implementations?
ChannelRSSFeedItem.java. Must be there on
bussiness/RSSChannelReader or as they act as value object must be on
models\. I have to say that I work with them in the windows/screens of my app. Or maybe to create an adapter to transform the result object generated by my
RSSChannelReader.java to my model object?
NetworkRequest.java should be in a different folder from
My real problem, I think, is that some responsibilities, in this case
ReadRSSChannel can produce other that can actuate as responsibilities for other responsibilities, for example my
NetworkRequest. I can use to read rss but also could be useful for download images.
Do I have to create a new folder for each responsibility?
I'm a little confused because my project is increasing and some files aren't place in the correct place. In some places my package name is too long with sub levels.