- See more at: http://blogtimenow.com/blogging/automatically-redirect-blogger-blog-another-blog-website/#sthash.YsVbCxL0.dpuf Journey to Becoming a Web Developer: Designing classes with single responsibility

Wednesday, November 20, 2013

Designing classes with single responsibility

The single responsibility principle is using classes in our application that each have only one responsibility. Classes that have more than one responsibility can become too convoluted and can break more easily. The type of programs we want to make involves creating code that is reusable. Classes that have more than one responsibility are difficult to reuse, so having classes that do one thing is very important. One question that I had while reading this was how would I know if the class I built only has one responsibility. The chapter gave some helpful tips on how to determine this. One was making the methods into a question. If the methods seems to be doing different unrelated things then we don't want that. Another was to describe the class in one sentence. If the sentence has "and" or "or" in it then the class most likely has more than one responsibility. Overall our class methods should all be related and work to towards one common goal.

No comments:

Post a Comment