Monday, November 26, 2012

Design Pattern - Factory Pattern

You might also like seeing Observer Pattern, Strategy Pattern and Decorator Pattern


The next Pattern is the Factory Design Pattern. This pattern is often confused with the Simple Factory.
The difference is that in the Factory Design Pattern it is the subclass that controls instantiation of the object.

An everyday example of  Factory Pattern is the Java Collections iterator. Depending on the sub-class we get different types of iterators that shares a common interface.

One Slider? Coming up




Tuesday, November 13, 2012

Design Pattern - Decorator Pattern

You might also like seeing Observer Pattern and Strategy Pattern.

The next pattern in the series is the Decorator Pattern. Simply put a decorator creates a new instance by decorating the current object with additional responsibility. One slide to remember the pattern? Here we go ...

Monday, November 5, 2012

Design Pattern - Observer Pattern

The wiki article is great introduction to the Observer Pattern.

Looking for a one slide to easily help remember the pattern? Here we go ...

 

Monday, October 29, 2012

Saturday, October 27, 2012

Design Pattern - The single slide series

Its sometimes hard to remember design patterns and their definitions specially if your new too them. The one slide series aims to associate an image with the design pattern to make it easy to remember the pattern quickly.


Saturday, January 7, 2012

JFactor - The Java Treasure Hunt

Java Treasure Hunt is a Java based online treasure hunt that I had conceived a long time back. With a few modifications, I've revived  it a few days back & I'm planning for a second hunt sometime this year!

For now do enjoy the very first JFactor  - The online Java Treasure Hunt. The hunt's is pretty tough and not a lot of people have made it through till the end! Hoping you folks have better luck this time around :)

Do leave a thought on what you think of it!

!!Wishing everyone a great and eventful 2012!!

Saturday, December 17, 2011

Understanding the XML Namespace

If your a java programmer the probability that you have run into XML configuration is pretty high. Many frameworks require XML based configuration and even when they offer alternatives (usually Annotations) they usually recommend using XML.

Whether you like it or not XML is everywhere.

So what exactly is the XML namespace. Many a times it just some boiler plate that's added to the beginning of a config document.


Use Spring? Here is what you might have,

<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xmlns:util="http://www.springframework.org/schema/util"
       xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
http://www.springframework.org/schema/util
http://www.springframework.org/schema/util/spring-util-2.0.xsd">

    <bean id="xyz" class="blogspot.javachats.XYZ"></bean>

    <util:properties id="someConfiguration" 
         location="classpath:blogspot/javachats/some.properties"/>
</beans>

So what is the XML namespace?

All the tags that start with xmlns form the XMLNameSpace tags.

In this example we have three namespaces defined - 1 is implicitly used (referred as Namespace Defaulting) and 2 are explicitly named (referred as Qualified Names). Were you able to identify which is which?

  1.  Namespace Defaulting
    The namespace xmlns="http://www.springframework.org/schema/beans" defines a default namespace. It means that a Non-Qualified tag against which it is written and any Non-Qualified child tags would by in that namespace. In case of the spring example above - the <beans> and <bean> element belong to the namespace http://www.springframework.org/schema/beans
     
  2.  Qualified Names
    The namespaces xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" and xmlns:util="http://www.springframework.org/schema/util" are qualified namespaces. It means any element that are prefix with xsi or util would be part of that respective namespace!
Did you spot where the namespace xsi is used in the example above?
Why do they matter?

In pretty simple terms the name of any XML element (referred as QName) comprises of the XML NameSpace + Local Name.
e.g. QName(Beans) = http://www.springframework.org/schema/beans/ + beans
This means two different XML element may have the same name in different Namespaces.

Namespaces in XML are the Java Equivalent of Packages!

That's XML Namespaces in nutshell1. Next time you look at some boiler plate XML - be sure to give it a second glance.

Foot Notes
  1. The XML Name Reference at w3.org