Featured

Welcome Message

“Architecture before Artifact”

Hi, welcome to my blog. I am  a software developer, and a data science enthusiast. This is my experience, and knowledge sharing blog on programming, software development, and so on. To be clear, I am blogging to remember the stuff that I need for my job, and if anyone is eventually helped by it, then he is welcome.

My book on software engineering has been released lately. It is named, “SOA into Micro service and integration of the changes”, ISBN: 978-3-330-00366-8

UML for Design Based Software Development

Before writing the actual code it is always handy to plan, and design what we want to build. There are so many ways to do so; UML (Unified Modelling Language) is one of them, and there are many types of UML diagrams, such as, Class Diagram, Use case Diagram, Component Diagram, Sequence Diagram.

In my personal opinion, writing codes without at least a class diagram seems very naive. Let’s see how class diagram can help us building a software rapidly.

Let’s assume we are given a task of reading an XML file, renaming the tags based on some given values, and generate a new XML file with the new tags. How would you map this problem!? If we just go for the coding right away, there is a higher chance of fragility somewhere during the development. So it is undoubtedly a better approach to draw a class diagram before writing the code. It doesn’t have to be precise, rather make it simple, and implementable.

As we can see from the diagram above that, we need three different classes to get the job done.  And also the implementation becomes easier, reduces our future thoughts when we design a UML diagram of a solution.

Dynamic Fibonacci

If we want to understand the true essence of dynamic programming, we should consider the simple example of fibonacci series. Using the conventional algorithm the time complexity of the solution is O(2^n).

``` def fibonacci(n):
i, a, b = 1, 0, 1
while(i<=n):
a, b = b, a+b
i += 1
return b```

But using the dynamic programming we can reduce the function call, as well as the time complexity to O(n).

```class Main {
int[] f = new int[100];

public int fibonacci(int n) {
f[0] = f[1] = 1;
for(int i=2;i<=n;i++) {
f[i] = f[i-1] + f[i-2];
}
return f[n];
}
}```

Greedy Algorithm

Greedy approach gives a feasible solution to a problem where multiple solutions are possible. Greedy approach doesn’t give you the optimal solution, but if the feasible solution is optimal, then we can accept that solution.

Let’s consider the coin changing problem, which could be solved using greedy algorithm. Assume that, we are given a set of coins, and a sum to be changed. Then we can do so,

```import math

def greedy(coins, target):
remaining = 0
count = 0
i = 0
times = 0
while(True):
if(target is 0):
break
else:
times = math.floor(target/coins[i])
remaining = target - (coins[i]*times)
target = remaining
print(coins[i]," needs: ", times," times.")
i += 1
count += times
return count```
```coins = [10,5,2,1]
print("\ntotal coins needed: ", greedy(coins, 31))```
```10  needs:  3  times.
5  needs:  0  times.
2  needs:  0  times.
1  needs:  1  times.

total coins needed:  4```

As we can see that, we need total 4 coins to make 31 from the list of [10,5,2,1] coins. In this case it is an optimal solution, but if we are given [4,3,1] for 6 then the total number of coins we need would be 3 using the greedy algorithm. Unfortunately, the optimal solution would be 2. So we see that greedy algorithm has some drawbacks, but it could be optimized using the dynamic programming.

Software Development Life Cycle

The termination of a software is considered to be the failure of the project. A software should be maintained, and optimized over the period of time. This is how a software turns into a technology, and that is where the success of a software belongs. In order to make a software project successful we need to follow the certain steps.

The figure drawn above shows the essential steps of the software development in my eyes.