Why and When to use Spring Framework : Part 1

September 23, 2008

It is really a tough deal for a new programmer to figure our why should he/she use a framework like Spring. Developer or programmers who worked with single tire framework like Struts or Hibernate may find it’s usability easier than everyone else. At the beginning of J2EE applications 1999/2000 (I was not even start my graduate school) it brings out a new fresh wave of in web based application through core middle-tire concepts. Though those applications takes much afford to develop and more complexity on overall process. Since new problems and challenges rushed to us day by day. J2EE and other web applications shows up with some crucial problems like followings:

J2EE applications usually carries excessive amounts of protocol code: Try/catch blocks for JDBC, or transfer objects requires a lot of bulk code that is totally unnecessary compare to business logic but mandatory for J2EE structure.
J2EE applications often use distributed object model: Distributed object model(a remote object whose methods can be invoked from another JVM, potentially on a different host) creates extra codes where most of those are simply duplication. Distributed application is much complicated than the co-located(same place) one.
Unit test in J2EE applications are tough The basic design of J2EE didn’t consider unit testing. As a result EJB and most of J2EE APIs are hard to test out side of server.
Over use of EJB: EJB was specifically designed for internally distributed and transactional applications. But it was used in many place where it was not appropriate.

It is proven by experience a framework is much flexible than traditional tool-enabled code generation. Configuring the behavior of simple piece of code much easier by using a framework. Many developers attempt to write a framework for these reasons. Spring comes up with solutions of many flexible facilities. Spring framework contains many features that help to commit a web application in a easier way. Here are some core features of Spring:

Inversion of Control (IoC): Most probably the best feature of this framework. Advertise the example of Hollywood principle of “Don’t call me, I will call you”. In traditional way of class library, Application code is responsible for total work flow. As a result calling out the class library is necessary. But by Inversion of Control framework code invokes application code, coordinate overall work flow.

Dependency Injection: A kind of IoC that maintains push configuration. At the runtime, the dependencies are pushed into application object. Thats why Dependency Injection objects never need to load custom properties or search a database to load configuration. The framework does the whole thing.

Aspect Oriented Programming (AOP): AOP separates crosscutting concerns into single units or aspects.

By: Md. Shahjalal

References:
1. http://www.wrox.com
2. Expert Spring MVC and Web Flow
3. Java Loby


Observer Pattern

September 21, 2008

Observer Pattern is a Design Pattern that defines one-to-many dependency between objects. As a result when one object is changes its state then all its dependents are notified and updated automatically. This design pattern is very help full for implementing a distributed event handling system system.

A very good example to describe the system can be Newspaper-Subscriber system. A client get a newspaper every morning is he/she subscribe to it. The newspaper company has no idea which people are their subscriber. The local agent send the copy to the client. When a client subscribe to a specific newspaper, he/she getting that from next day. And when they unsubscribe from that they don’t get that copy anymore. Now consider publishing a newspaper is like occurring an even. After publish all its client get a copy which is like get a notification. The basic functionality used run this pattern. Subscribe or attach, Unsubscribe or detach, Notify(),

Some Programming language like JAVA contains API for working with such sort of Pattern. java.util.Observable provides basic functionality for creating such Subject or event source. Along with this java.util.Observer provides same for an observer or client. One of the best example of this pattern is Java GUI implementation. Pressing a button introduce an action on which it is subscribe to. The addActionListener method subscribe to a task.

You can find a java implementation of this pattern in wikipedia

By: Md. Shahjalal


What is Design Pattern ?

September 14, 2008

Think about our high school mathematics. I know those sucks. There are only few things that help us to less our misery :D One of those are some predefined equation. Like (a+b)^2 or Pythagoras equation of c^2=a^2+b^2. We have applied these equations whenever they are applicable to customize the burden of the size of the math. Design Pattern is much similar to those equations. Which is a general reusable solution for common types of problem faced in most software development process all over the world. It is a collection template that can be used to solve or code your problem or program in enterprise world. A common variety of problem arises in different levels of software development. Design Pattern deals with those in a well defined and mostly accepted way.

Design Pattern fuels the development process through well tested and proven development concept. It is consists of several sections. Basic of design patten are classified into following sections:
1. Creational patterns
2. Structural patterns
3. Behavioral patterns
4. Concurrency patterns

1. Creational patterns consists of
a. Abstract factory
b. Factory method
c. Builder
d. Lazy initialization
e. Object pool
f. Prototype
g. Singleton
h. Utility

2. Structural patterns consists of
a. Adapter
b. Bridge
c. Composite
d. Decorator
e. Facade
f. Flyweight
g. Proxy

3. Behavioral patterns Consists of
a. Chain of responsibility
b. Command
c. Interpreter
d. Iterator
e. Mediator
f. Memento
g. Observer
h. State
i. Strategy
j. Specification
k. Template method
l. Visitor
m. Single-serving visitor
n. Hierarchical visitor

4. Concurrency patterns Consists of
a. Active Object
b. Balking
c. Double checked locking
d. Guarded

By: Md. Shahjalal

Sources:
1. WikiPedia
2. Head First Design Pattern
3. patterndepot.com


Follow

Get every new post delivered to your Inbox.