Tuesday, May 17, 2011

Divide & Rule

"Divide & Rule" also known as  divide and conquer is a very famous way to attack the problem. History witnessed this strategy work in very complex situation. It is very famous in political and military circle. It is used to influence countries, win wars and play a big role in international politics.
In corporate people also take the help of this rule frequently. In Computer Science Design of Algorithm classes it is one of technique to attack a problem.
Mostly when we plan for enterprise software previous experience says that maintenance is more costlier than developing.  With time requirements, business rules change for which  maintenance is really necessary. As Change is the only constant in this world, we can not avoid the situation. So maintainability is the highest precedence while designing or developing an application. That is the reason Object Oriented languages (Java, C#, C++ etc.) are popular. They have the feature to mange the complexity of software better than procedural language. So basically OO design means managing the complexity. Divide the complex functionality into integration of smaller/maintainable  component. How to and what extend to divide ... These are some decision which designer has to take to have a optimum solution.
So next time we face a problem this will be an handy technique to approach it ......

Friday, May 6, 2011

Web services are Self Service

In my college days ... There used to be a techno fest. It is completely organised by students starting form event planning, marketing and execution. All students were contributing in some way. With some friends I had planned to put a food stall in the college for event. The college campus was 20km away from city, and in the event normal canteen service is shutdown. So food stall is hot cash business in that situation. We wanted to make some money by creating some value.But we had no idea how to manage a restaurant for two days. We decided to buy foods from a restaurant from the city and we will serve the same food in our stall with some higher price.
And the idea worked we made some handsome profit. And the students also appreciated the food quality.....

Some time to provide some service to end user the service provider need to consume some other service. In this scenario a system need to use service/resource of another system. If it happens on web (www) then it is called web service. It is a standard way how two system can interact. Normally one system host some service the other consume. At the end of the day user get the complete service :)

Monday, March 21, 2011

Spring king of all season

Most of the developer worked in Java is aware of spring frame work. And who doesn't know anything about Spring framework can think about experienced spring season. Like many other frame works available Spring also serve as container. It creates the java object/component run time and manage them. The application developer can concentrate on business logic and really forget about managing objects. When people talk about Spring two terms dependency injection and inversion of controller always comes. Let me also write about these... When there is a situation a object use another object (association).
Lets have an example:
Class Orchestra                  
{
     Dancer  dancer = new Dancer();
     Singer   singer = new Singer();
     perform()
       {
           dancer.dance();
           singer.sing();
       }
}

Here Orchestra class use Dancer and Singer to perform the job.  Well tomorrow we need some modern dancing and some different kind of Song we have to change the Orchestra class.
In Spring way we can re write some thing like below.

Class Orchestra                   
{
     IDancer  dancer;
     ISinger   singer;
     perform()
       {
           dancer.dance();
       singer.sing();
       }
}

Interface IDancer
{
   dance();
}

Interface ISinger
{
   sing();
}

BreakDancer implements IDancer
{
  dance()
   {
     ----
     ----
   }
}
RockSinger implements ISinger
{
  sing()
   {
     ----
     ----
   }
}

In Runtime we can inject the dancer and Singer to Orchestra using Spring. Well here with singer and dancer we are injecting the dependency to Orchestra. And Orchestra gave the control which kind of dancer and singer is going to perform. This is something called inversion of control.  We can do both xml based or annotation based configuration in Spring. Here is the xml version
<bean id="orchestra" class="com.action.Orchestra">
     <property name="singer"><ref bean="rockSinger"/></property>
    <property name="dancer"><ref bean="breakDancer"/></property>
</bean>
<bean id="rockSinger">
    <property name="target">
            <bean class="com.action.RockSinger" />
        </property>
</bean>
<bean id="breakDancer">
    <property name="target">
            <bean class="com.action.BreakDancer" />
        </property>
</bean>         


So spring gives such a environment where  we have all the freedom to configure anything up to any level.
Have a nice time in Spring :)