Interface Segregation Principle explained with simple example

Interface Segregation Principle (ISP) is a software design principle which states that “many client specific interfaces are better than one generic interface“. This principle enforces to implement only usable methods which will reduce coupling between modules. This principle ensures that any client should be dependent only on those methods which they use.

Before going ahead we should know why do we need software design principle and what is software design principle.

(more…)
Interface Segregation Principle explained with simple example Read More

Liskov Substitution Principle explained with simple example

Liskov Substitution Principle (LSP) is a software design principle which states that “derived class objects should be completely replaceable by their base classes“. This principle ensures that any derived class extending base class will not change their behaviour.

Before going ahead we should know why do we need software design principle and what is software design principle.

(more…)
Liskov Substitution Principle explained with simple example Read More

Open/Closed design principle explained with simple example

Open/Closed design principle is a software design principle which states that every module, class or function of a software should be open for extension but closed for modification. This design principle ensures any new functionality can be added via new classes which means minimum code changes required in existing classes.

Before going ahead we should know why do we need software design principle and what is software design principle.

(more…)
Open/Closed design principle explained with simple example Read More

Single Responsibility Principle explained with simple example

Single Responsibility Principle (SRP) is a software design principle which states that every module, class or function of a software should have one and only one responsiblity/functionality to perform. As stated by Robert C.Martin, “A class should have one and only one reason to change“.

Before going ahead we should know why do we need software design principle and what is software design principle.

(more…)
Single Responsibility Principle explained with simple example Read More

Software design principle explained with simple example

Software design principle consists a set of guidelines invented by Robert C.Martin to avoid bad software design. These guidelines consists of five design principles for object oriented software development. These design principles are:

Together these are called SOLID design principles.

(more…)
Software design principle explained with simple example Read More

Why do we need Software Design Principles

Object oriented software development often becomes victim of non-maintainable, unreliable etc in long run in most of cases. Lot of people might put bad coding skills behind that state (which is true sometime) but bad software design is the actual culprit which will make excellent coders write bad code because software design doesn’t allow them to do so.


Always remember knowing what not to do is more important than what to do !!!

(more…)
Why do we need Software Design Principles Read More

Finding number of ways to write “n” as sum of multiple smaller numbers

This problem can be solved using multiple approaches but here we will solve this problem using Dynamic Programming and showcase how dynamic programming will make the execution super-fast.

We will go through with the same steps as mentioned in Dynamic Programming post to tackle this problem step by step for better understanding.

Let’s explain the problem,

given n, find the number of different ways to write “n” as the sum of 1, 3, 4

Example:

for n = 5, the answer is 6

5 = 1+1+1+1+1

   = 1+1+3

   = 1+3+1

   = 3+1+1

   = 1+4

   = 4+1

Let’s apply the 3 Steps rule to tackle this problem.

(more…)

Finding number of ways to write “n” as sum of multiple smaller numbers Read More

Dynamic Programming approach explained with simple example

Dynamic Programming is a programming technique which is used for solving complex problems by breaking it into comparatively simpler subproblems and finding the optimal solutions of the complex problems by finding the optimal solutions of these subproblems.

Even though, the name “Dynamic Programming” might scare people but actually its kind of simple if we follow some basic techniques to approach any complex problem.

Steps to tackle a problem using Dynamic Programming approach:

1) Define smaller problems from the original complex problems.

2) Solve these smaller problems using recursion.

3) Use smaller problems results to solve the bigger complex problem.

(more…)

Dynamic Programming approach explained with simple example Read More

Heap sort explained with simple example

Heap sort is one of the fastest sorting algorithm, which works on Divide and Conquer algorithm. In this sorting algorithm, all the data elements are inserted into a heap (max or min) and then removes item from the root of the heap will give the sorted(descending or ascending) data list.

Pros:
1) Faster algorithm and best performance O(nlogn).
2) Simple implementation.
3) No extra space is needed.
4) Good for cases to find biggest/smallest or top k biggest/smallest element finding kind of scenarios.

Cons:
1) Not a stable sort means position of relative identical data items is not guaranteed.

(more…)

Heap sort explained with simple example Read More

Quick sort explained with simple example

Quick sort is one of the fastest sorting algorithm, which works on Divide and Conquer algorithm. In this sorting algorithm, an element is picked as a pivot element and list is divided into sub-lists around the pivot element. These divided sub-lists finally sorted into which results into sorted initial list.

Pros:
1) Faster algorithm and best performance O(nlogn) is for worst distribution case scenario.
2) Simple implementation due to recursive nature.
3) No extra space is needed.

Cons:
1) Worst case scenario performance is O(n*n).
2) Not good for Linked list kind of sorting data where memory is not contiguous.

(more…)

Quick sort explained with simple example Read More