This entry extends the one about object-oriented design. Unlike the broad focus of that article, this one focuses on a more specific topic – the Single Responsible Principle (SRP). However, SRP is too broad a topic to be discussed pithily. As a result, the subsequent article focuses on the more parochial topic, implementing SRP in a simple way. As a means for achieving that goal, tips are provided by the list below. The implementation of those tips is demonstrated by the accompanying code.
The aforementioned tips are not a formula. Occasionally, the preceding tips might not be prudent to use, so one must implement them judiciously. However, do not become too hung up on that caveat. If one uses a tip injudiciously, at some point the affects of that misuse should become apparent. Even if the point of that discovery is at an inopportune time, the windfall of such a discovery does teach valuable lessons – ones that are often not forgotten. As a result, feel free to make mistakes. However, one must still be mindful of the aforementioned caveat, as judiciousness must always be exercised when designing software.
Object-oriented design is a topic about which dozens of books have been written. I do not wish to replace those lengthy tomes with this blog entry. However, this blog entry does intend to provide a basic means to write better code. The provided means are the rules below. There are some exceptions to those rules, so they are not ironclad. However, following them generally will lead you to write better code. In addition, the code that implements these rules is available for download.