Tag Archives: Object oriented principles

Single Responsibility Principle with Java Code Example

single responsibility principle with Java example

Single Responsibility Principle (SRP) is one of the most important object-oriented coding principle which, if followed religiously, can help you write a very good quality code. Here is what SRP states: A block code representing class or method should have just one reason to change In other words, Single Responsibility Principle can be stated as the following: A block of code representing class or a method should do just one thing and do it very well In yet another words, SRP can also be stated as the following: A block of code representing class or method should have just one responsibility or serve just one functionality Pictorially, decide for yourself …

Continue reading

Posted in Maintainability, Reusability, Software Engg, Software Quality. Tagged with , .

Multiple Classes with Single responsibility VS Single Class with Multiple Responsibilities

While taking a session with a set of mobile developers, one of them asked a question that made many of them curious. Why multiple classes when single class can do? The main reasoning for single class was that one would be able to save some lines of code. Also, one would be required to create just one object for multiple functionalities. Lets look at some of the key advantages of multiple classes, each one of them having single functionality. High in cohesion, and hence reduced coupling. This tends to make the class reusable. Lesser costly to change than single class. Following explains the cost structure related with a change: Let’s …

Continue reading

Posted in Maintainability, Software Quality. Tagged with , , , .