What is Spring


What is Spring


This will be a quick explanation summarized to allow a faster understanding.

Quite simply spring is a framework that uses XML and Java it was built and released by Rod Johnson in 2002 and was featured in his publication on j2ee entitled Expert One-on-One J2EE, it is new although relativity new in technology standings, the MVC hasn't really kicked off yet due to lack of support because of it's basically full control aspect, host servers would be vulnerable to exploit due to the fact that it uses what can be a machine level language.

Spring allows POJO (plain old Java objects) this means it uses normal Java to work no special needs apart from basic set-up i.e. telling the program it uses spring and using interfaces rather than just code.

Inversion of control


An interface is basically the same as a header file in C++ that allows the declaration of abstract methods in a Java application.


Spring is against the concept of tightly coupled coding.

Coupling

Imagine you have a fish tank program and in that tank you have one fish swimming around.  The program needs to calculate the tide flow in that fish tank that would be effected by the fishes movements in the water. coupling is the amount of dependence methods have in each other.

Tightly coupled

In a tightly coupled program  you would have two classes one would be the fish and the other would be the water.

In the water class the fish class would be called to get direction of the fish and the speed of the fish this would then be used to calculate the tide.

That sounds fine but in the fish class the water class would be called to get the movement of the water and the strength of the stream.

This would then be used to calculate how fast the fish can go in the direction it wants to go and how much force it needs to get their.

The problem in this is the fact that if you change one thing in the fish class you would need to change the water class.

 i.e. If the fish has specific features and the programmer knows this he might code with these features in mind. this would be a tightly coupled application because if you add another fish to the tank you would need to change the code to accept the new fish as well as the old fish.

Decoupled code

What if you had a separate class for everything now, let's say fish class, force class, tide class, collision class etc, this would be more decoupled because unlike the example above with only two classes.

If you want to add another type of fish to that tank you could still need to change the code if its coupled. Because the fish and the water class talk directly to each other they need each other to work yes but are they cohesive. meaning no matter how you separate your code if their tailored to one purpose they will always be tightly coupled.

Cohesion 

This can be how two method work together, to try and make it clear lets go back to the fish tank example.

fish class wag_tail() method calls water class fish_moves(left) and the tide class makes the water move right at a speed of 2 mph.

whats wrong with this is if you have another fish and its tiny and its tail wags left the tide will still move 2 mph right that's because its too dependent on the other fish where a tail wag releases 2 mph worth of power, another issue with that is that is what if the fish is swimming fast, a wag would need to give variant power levels.

how to fix it is simple.

fish_moves(left, 1 mph)

just adding that allows a great difference.

Meaning a code made for ones pacific purpose can probably do that one task well but not another one, so if I added another fish to the tank unless it's the exact same fish we would need the change the code to except different things.

 building decoupled code basically means building code that's not specific, one that you can simple add a code to without changing all its dependents.

No comments:

Post a Comment