Thursday, November 17, 2011

REST

For quite sometime I have been looking for a good tutorial on rest that is simple and to the point. Finally I found one...here it is.
http://rest.elkstein.org/

Thanks

keep thinking....

Monday, January 31, 2011

Azure and clouds computing...


ou have to travel from point A to point B on a regular day-to- day basis. You have two options.

Option 1: You can buy a nice car and drive it yourself(or even hire a driver) from Point A to B
Obviously you have to consider  the cost of the car since you have to buy the car, then you pay for the gas. Because of too much of use the car will need maintenance, servicing, tire change and your overall cost slowly goes up. You may decide not to travel from point A to point B any more and in that case you end up selling the car at the half price you had bought it for.

Option 2: You can get in a luxury Bus that goes from Point A to point B and share the cost with other passengers. You don’t have to drive it instead you enjoy the ride. You don’t pay for the gas, maintenance, tire change and you don’t pay the driver's salary. You buy the ticket only on the days when you are travelling. If you stop going from point A to point B, you simply stop buying the ticket. Basically you pay only for how much you use the bus and don’t pay on the days when you don’t use it.

The second option is much feasible and SCALABLE. The reason I call it scalable is because a Bus can carry 50 passengers from point A to point B at a very low cost to individual passenger as compared to buying your own car to do the same  thing. You can think of this option as CLOUD COMPUTING in virtual world.

Business Scenario:  there is a small startup online company. In order to go online they need to buy servers, network, RAM, space hardware and lots of software costs like servers, sql and data center cost. This will also include hiring the IT people  to setup the network.
Case1: this company does an excellent job and they now have 10x customers, which means they add more software licenses, more hardware and buy more bandwidth from data center to scale to the increased number of customers. Therefore they face the scalability issues as a result of doing good business.
Case2: Lets say this company didn’t do well, as a result they are in loss with hardware, software, data center costs and other costs. All this is now a waste.

Solution: Pay per use is the solution. This is a model where you are sharing the hardware, software, IT maintenance, bandwidth and all other costs. This is nothing but cloud computing and compare it with our luxury bus. Now if your business was good or bad the cost of closing the business or scaling to x number of customers will significantly reduce the cost. There are so many providers that provide the could computing

Cloud computing is like a platform where you host your application and forget about everything else because it will allocate all the resources that your application will need based on its requirements.

Will cover more in next session….keep thinking and remember the luxury bus is the future:)

Saturday, January 15, 2011

Factory Pattern

What does a factory do? It creates something, it constructs something. Therefore the category of this pattern is Creational Pattern, no surprises!

For the sake of simplicity, let's say that a car consists of three components: Engine, Chassis, and Steering. Naturally, you can't have the same types of Engine, Chassis or Steering in each car, because then the cars would all be the same. It won't do to mix-and-match components, either. You need all Honda parts to go with the Honda, and all BMW parts to go with the BMW, etc. The different parts of the cars don't need to do the same thing, either: they need merely conform to an interface. Let's encapsulate the decision making process for assigning the parts when you build a car.
Should the main car building program care what kind of car is being built? No, it shouldn't. It should just expect the car to behave as all cars should, and not care about the specifics

Imagine you have a code that has multiple if and else statements where you create object of different classes depending on the conditions.  You will end up with lots of use of 'new' keyword.

if(type = "honda")
       hondaObj = new Honda()
Else if(type = "bmw"
      bmwObj = new BMW()
….
….
so on...

 This definitely makes the code little complex. Also if in future you have one more condition to be added in the pile, you create another object based on that type. One more problem with this approach is that you have to know the type of these classes to create their objects and this problem becomes worse when such a code is written by some client side application, which means that client application has to know these types in order to create and use these objects, which is a bad design and definitely not scalable.

Solution to these two issues is…
  1. Make an interface called IVehicle and drive the concrete classes from this class and client will know only this interface and doesn’t have to know the names of the classes..
  2. Introduce a factory class which will be responsible for creating the classes which will know the different classes, therefore you supply the type and it returns the object.

This solves both the issues mentioned above. The above code now looks like below…
IVehicle  objVehicle;
objVehicle = factory.GetVehicle(type);
objVehicle.GetModelNUmber();

Keep thinking….

Saturday, January 8, 2011

Composite Pattern

You have a lots of objects in your project that are similar looking but they implement differently. This pattern allows us to treat these different objects in the same uniform manner. In a nutshell composite pattern is a basic implementation of an Interface.

Here is an example to explain this pattern in a very simple way:-
 My son was playing with wooden blocks of various shapes and that was the time I thought of this example. All these blocks have their own shape i.e. Rectangle, Square, Circle and Triangle.

If we were to implement classes to represent these objects then we will simply define 4 classes i.e. Rectangle, Square, Circle, Triangle and add their corresponding Draw method to the class definition. It becomes pretty straight forward if you just define an Interface called IShape with a method called Draw and make all the classes to implement this interface. This makes sure that all the classes  are now forced to implement Draw method.

When my son is finished playing with these shapes, he simply collects them back to a box meant to store these shapes.

ArrayList Box  = new ArrayList();
Box.Add(objRectangle)//treat everyone equal and same
Box.Add(objSquare)//treat everyone equal and same
Now I can draw them all in one simple loop
For each(IShape shape in box)   //treat everyone equal and same
{
shape.Draw();
}

Bottom-line: Ask yourself a question before implementing this pattern: "Do I have multiple similar looking objects that need a uniformity?" If the answer is yes, then go for this pattern!

Wednesday, January 5, 2011

Decorator Pattern

This is the most simple design pattern of all the patterns. Decorator patterns is nothing but its implementation of inheritance concept in object oriented model. They fall under the structural category of pattern types as they help in organizing the design of various objects, classes in the project structurally.

You have a class called MyClass and it has a method called Something() defined in this class. Now you also have a class called MySubClass that is inherited from MyClass. So you add another method called SomethingMore() in this inherited class to add something more to base implementation Something().

Therefore this pattern simply suggests using and encouraging the concept of inheritance, that’s all there is to this pattern.

Until next post….Keep thinking….

Design Patterns....

You get a problem to solve, you realize that this is nothing new and people must have already solved it. You look for the best fitting solution to your problem, it is highly likely that you will find a solution that perfectly matches your problem definition. What you have found is nothing but a design pattern.

Design patterns are nothing but they are solutions to the most common problems that we face in our day to day life. They are already documented, tried and tested from time to time by generations. If by any chance you don’t find a solution to your problem definition(every problem is a different problem) then you have a chance to invent a new design pattern. Therefore the patterns are not fixed in number and you may have a unique problem that will need a design pattern that is not defined already. It may happen that you have more than one patterns that appear to be solution to your problem, it complete depends on you to choose a pattern for your problem, as I said every problem is different and choose a solution that best meets you requirements to keep things simple.

There are three main categories of design patterns
Creational: These patterns will control the creations of objects in the projects
Structural: Controls and decides the structural aspects in the project
Behavioral: Controls the behavior of your objects in a project

There are around 35 patterns that are already defined in above categories. In my following posts I will try to explain these patterns in most simple language as I understand them.

Until then..keep thinking!