Skip to main content


Showing posts from October, 2014

Open Close Principle with example in Java

Open close principle Bertrand Meyer coined the term open close principle in his 1988 book Object Oriented Software Construction . Software entities like classes, modules and functions should be " open for extension but closed for modifications ". It is a generic principle. You can consider it when writing your classes to make sure that when you need to extend their behaviour you don't have to change the class but to extend it. When referring to the classes Open Close principle can be ensured by the use of Abstract classes and/ or Interfaces and concrete classes implementing their behaviour. This will enforce having concrete classes implementing Abstract classes/ Interfaces instead of changing them.  Some particular cases where this principle is used are Template Design Pattern, Strategy design pattern . We want to draw different kind of images. For this, We wrote a generic class ImageEditer which can draw shapes. See the below code snippet. package javawi

Single Responsibility principle with example

Single Responsibility Principle Single responsibility principle was introduced by Tom DeMarco in his book " Structured Analysis and Systems Specification, 1979 ". Robert Martin reinterpreted the concept and defined the responsibility as a reason to change. A class should have only one reason to change. In this context, responsibility is considered as reason to change. This principle states that if we have two reasons to change for a class, we have to split the functionality in two classes. Each class will handle only one responsibility and on future if we need to make one change we are going to make it in the class which handles it. When we need to make a change in the class having more responsibilities the change might affect the other functionality of the classes. Let's see this by example. package com.gauravbytes.srp.parser ; import ; class FileParser { public void parseFile ( File file ) { // parse file logic for xml, csv, json

Introduction to Software Design Principles

What are Software design principles? Software design principles represent a set of guidelines that helps us to avoid having a bad design. Associated to Robert Martin who gathered them in “Agile Software Development: Principles, Patterns, and Practices". According to Robert Martin there are 3 important characteristics of a bad design that should be avoided: Rigidity:  It is hard to change because every change affects too many other parts of the system. Fragility:  When you make a change, unexpected parts of the system break. Immobility:  It is hard to reuse in another application because it can't be disentangled from the current application. What does SOLID stands for? S: Single responsibility principle . O: Open close principle . L: Liskov's substitution principle. I: Interface segregation principle. D: Dependency inversion principle.