Software Design

Open Closed Principle

Posted on

Take advantage of OCP to write highly extendable and maintainable software. Introduce new changes with minimal impact on the existing system. OCP seems to increase complexity of code due to abstraction levels it introduces. Embrace it pragmatically, find good candidates for OCP while designing software. OCP states, our classes should be open for extension but closed for modification. Whenever we have to implement a change or add new functionality, instead of changing the existing class we should extend the functionality of existing class. Let’s try to understand with a scenario below. In our example for Single Responsibility Principle, we used a logger to log exception messages to a text file. In future we may have a requirement to log some error messages to database or application even log. How should we design our software to allow extension to logging functionality in future? Let me code: For OCP example I have […]

Software Design

Single Responsibility Principle

Posted on

Use SRP guidelines to write loosely coupled and highly cohesive software units which can be reused. This makes the software extendable and maintainable.  Classes and interfaces are basic units of a software. While writing a software we often overload a class with multiple responsibilities. As name suggests SRP states that a class should only perform one responsibility. Let me code Let’s take a look at the example below for more clarity on SRP.

At a glance you may like the code and decide to go along with this. Hold on, let me explain the problems in this code in the light of SRP. This class is performing 3 different responsibilities. Launch the campaign. Notify all the subscribers. If some exception occurs, log the exception with some message. This is the violation of SRP. In future if we have to change the way we log our exception messages e.g. we want to […]

Software Design

SOLID Programming Principles

Posted on

SOLID programming principles have caught too much attention recently. There are many articles on SOLID principles that explain them superbly. My focus here would be to start with a simple example and apply these principles to see how we can shape up our code to match the Characteristics of a Good Software. I would show how we can achieve these characteristics by following the SOLID principles. SOLID is an acronym for S – Single Responsibility Principle (SRP) O – Open/Closed Principle (OCP) L – Liskov Substitution Principle (LSP) I – Interface Segregation Principle (ISP) D – Dependency Inversion Principle (DIP) Single Responsibility Principle (SRP) Use SRP guidelines to write loosely coupled and highly cohesive software units which can be reused. This makes the software extendable and maintainable.  Classes and interfaces are basic units of a software. While writing a software we often overload a class with multiple responsibilities. As name suggests […]

Software Design

Writing a Good Software

Posted on

What is a good software? This question might seem trivial but software gurus have defined a set of characteristics and in order to be good a software must exhibit either all or a subset of these characteristics. From a developer’s point of view some of these characteristics are very important. Let me explain them briefly here Maintainability: Changes/modifications are inevitable during the life cycle of a software. A software is said to be maintainable if developers can incorporate the changes with minimum effort and minimum impact on the existing functionality. Scalability: A software is said to be scalable if it can entertain the increasing number of users over the time. Extendability: Adding new functions to the software should be easy. Reusability: Divide the code into reusable units. These units should be loosely coupled and highly cohesive. Testability: Test driven designs (TDD) makes sure we write testable code. Writing automated tests has […]