<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Vinothbabu&#039;s Desk! &#187; Design Patterns</title>
	<atom:link href="http://vinothbabu.com/category/javaj2ee/design-patterns-javaj2ee/feed/" rel="self" type="application/rss+xml" />
	<link>http://vinothbabu.com</link>
	<description>When Smart becomes Dumb!</description>
	<lastBuildDate>Thu, 01 Mar 2012 10:38:23 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Creational Patterns &#8211; Abstract Factory Pattern</title>
		<link>http://vinothbabu.com/2010/08/09/creational-patterns-abstract-factory-pattern/</link>
		<comments>http://vinothbabu.com/2010/08/09/creational-patterns-abstract-factory-pattern/#comments</comments>
		<pubDate>Mon, 09 Aug 2010 11:09:20 +0000</pubDate>
		<dc:creator>Sachin</dc:creator>
				<category><![CDATA[Abstract factory pattern]]></category>
		<category><![CDATA[Creational pattern]]></category>
		<category><![CDATA[Design Patterns]]></category>
		<category><![CDATA[featured]]></category>

		<guid isPermaLink="false">http://vinothbabu.com/?p=312</guid>
		<description><![CDATA[Today we are going to see one of the design patterns abstract factory. Its one level of abstraction higher than factory pattern.The main use of Abstract Factory Patten is that is isolates the concrete classes which are generated. Do we need the names of actual implemenating classes? The names of actual implementing classes are not [...]]]></description>
			<content:encoded><![CDATA[<p>Today we are going to see one of the design patterns abstract factory. Its one level of abstraction higher than factory pattern.The main use of Abstract Factory Patten is that is isolates the concrete classes which are generated. <span id="more-312"></span><strong>Do we need the names of actual implemenating classes? </strong></p>
<p>The names of actual implementing classes are not needed to be known at the client side. Because of the isolation, you can change the implementation from one factory to another. This means that the abstract factory returns the factory of classes.</p>
<p>Since being a die hard fan of RajiniKanth, let me get into his style of explaining things with an example. Let us go with an requirement where we are choosing our team for the current project.</p>
<p>[codesyntax lang="java5"]</p>
<pre>public abstract class ResourceManager {
public abstract Specs getTeamSize();
public abstract Specs getTeamsManager();
public abstract Specs getTechnology();
}// End of class</pre>
<p>[/codesyntax]</p>
<p>This class, as you can see, has three methods all returning different Specs of Resources Needed. They all return a method called Specs . The specification will be different for different types of Projects. Let’s have a look at the class Specs .</p>
<p>[codesyntax lang="java5"]</p>
<pre>package creational.abstractfactory;
public class Specs {
public String specification;
public Specs (String specification) {
this.specification = specification;
}
public String getSpecification() {
return specification;
}
}// End of class</pre>
<p>[/codesyntax]</p>
<p>And now lets go to the sub-classes of ResourceManager . They are Google, Davita and Yahoo.</p>
<p>[codesyntax lang="java5"]</p>
<pre>package creational.abstractfactory;
public class Google extends ResourceManager {
public Specs getTeamSize() {
return new Specs ("25");
}
public Specs getTeamsManager() {
return new Specs ("Vivek");
}
public Specs getTechnology() {
return new Specs ("Java");
}
}// End of class</pre>
<p>[/codesyntax]</p>
<p>[codesyntax lang="java5"]</p>
<pre>public class Davita extends ResourceManager {
public Specs getTeamSize() {
return new Specs ("30");
}
public Specs getTeamsManager() {
return new Specs ("Vinothbabu");
}
public Specs getTechnology() {
return new Specs ("Flex");
}
}// End of class</pre>
<p>[/codesyntax]</p>
<p>[codesyntax lang="java5"]</p>
<pre>public class Yahoo extends ResourceManager {
public Specs getTeamSize() {
return new Specs ("10");
}
public Specs getTeamsManager() {
return new Specs ("Padmanaban");
}
public Specs getTechnology() {
return new Specs ("DOT NET");
}
}// End of class</pre>
<p>[/codesyntax]</p>
<p>Now let’s have a look at the Abstract factory which returns a factory “ResourceManager ”. We call the class ResourceType.</p>
<p>[codesyntax lang="java5"]</p>
<pre>package creational.abstractfactory;
public class ResourceType {
private ResourceManager resm;
public static void main(String[] args) {

ResourceType type = new ResourceType();
//ResourceManager resourceManager = type.getClientName("Google");
System.out.println("Monitor: "+computer.getTeamSize().getSpecification());
System.out.println("RAM: "+computer.getTeamsManager().getSpecification());
System.out.println("Processor: "+computer.getTechnology().getSpecification());
}
public Computer getClientName(String resourceType) {

if (resourceType.equals("Google"))
resm = new Google();
else if(computerType.equals("Davita"))
resm = new Davita();
else if(computerType.equals("Yahoo"))
resm = new Yahoo();
return resm;
  }
}// End of class</pre>
<p>[/codesyntax]</p>
<p><strong>Conclusion:</strong></p>
<p>Abstract factory pattern centralizes decision of what factory to instantiate. Abstract Factory can be used as an alternative to Facade to hide platform-specific classes.</p>
]]></content:encoded>
			<wfw:commentRss>http://vinothbabu.com/2010/08/09/creational-patterns-abstract-factory-pattern/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Singletons in Java</title>
		<link>http://vinothbabu.com/2010/07/16/singletons-in-java/</link>
		<comments>http://vinothbabu.com/2010/07/16/singletons-in-java/#comments</comments>
		<pubDate>Fri, 16 Jul 2010 10:14:41 +0000</pubDate>
		<dc:creator>Sachin</dc:creator>
				<category><![CDATA[Creational pattern]]></category>
		<category><![CDATA[Design Patterns]]></category>
		<category><![CDATA[JAVA/J2EE]]></category>
		<category><![CDATA[Singleton pattern]]></category>

		<guid isPermaLink="false">http://vinothbabu.com/?p=306</guid>
		<description><![CDATA[Singletons are the design pattern when you want only one instance of a class created. You make the constructor private, and give access to the instantiated object via a static instance method that creates the object if it has not been created already. The singleton class is threadsafe lazy instantiation. I hope many would be [...]]]></description>
			<content:encoded><![CDATA[<p>Singletons are the design pattern when you want only one instance of a class created. You make the constructor private, and give access to the instantiated object via a static instance method that creates the object if it has not been created already.<br />
The singleton class is threadsafe lazy instantiation. I hope many would be knowing on lazy instantiation. With lazy instantiation, a program refrains from creating certain resources until the resource is first needed &#8212; freeing valuable memory space. In lame man words, loading the resource only when its needed.<br />
[codesyntax lang="java5"]<br />
public class YourSingletonClass{<br />
private static YourSingletonClassinstance = new YourSingletonClass();<br />
public static YourSingletonClass getInstance(){<br />
return instance;<br />
}<br />
private YourSingletonClass(){<br />
}<br />
}<br />
[/codesyntax]<br />
<strong>How do we ensure only one the same instance is returned?</strong></p>
<p>We write a public static getter or access method to get the instance of the Singleton Object at runtime. First time the object is created inside this method as it is null. Subsequent calls to this method returns the same object created as the object is globally declared (private) and the hence the same referenced object is returned.</p>
]]></content:encoded>
			<wfw:commentRss>http://vinothbabu.com/2010/07/16/singletons-in-java/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

