<?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>Hello Thupten &#187; &#187; factory method design pattern</title>
	<atom:link href="https://www.thupten.feedback/tag/factory-method-design-pattern/feed/" rel="self" type="application/rss+xml" />
	<link>https://www.thupten.feedback</link>
	<description>Just another developer&#039;s blog</description>
	<lastBuildDate>Sat, 20 Jun 2026 21:18:42 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=4.2.2</generator>
	<item>
		<title>Factory method design pattern</title>
		<link>https://www.thupten.feedback/2010/06/09/factory-method-design-pattern/</link>
		<comments>https://www.thupten.feedback/2010/06/09/factory-method-design-pattern/#comments</comments>
		<pubDate>Wed, 09 Jun 2010 08:45:01 +0000</pubDate>
		<dc:creator><![CDATA[thupten]]></dc:creator>
				<category><![CDATA[OpenOffice]]></category>
		<category><![CDATA[design pattern]]></category>
		<category><![CDATA[factory method design pattern]]></category>

		<guid isPermaLink="false">http://thupten.veryusefulinfo.com/?p=62</guid>
		<description><![CDATA[OpenOffice.org development heavily uses the Factory method design pattern. Design patterns are conventional templates that describes how to solve common software problems. Since most developers are familiar with the patterns, they can recognize a pattern in others source code. That makes working in teams easier. There are many popular design patterns. One of them is [&#8230;]]]></description>
				<content:encoded><![CDATA[<a href="http://thupten.feedback/wp-content/uploads/2010/06/Factory_1.png"><img class="size-full wp-image-74 alignright" title="Factory_1" src="http://thupten.feedback/wp-content/uploads/2010/06/Factory_1.png" alt="" width="200" height="165" /></a>OpenOffice.org development heavily uses the Factory method design pattern.

Design patterns are conventional templates that describes how to solve common software problems. Since most developers are familiar with the patterns, they can recognize a pattern in others source code. That makes working in teams easier. There are many popular design patterns. One of them is Factory method pattern.

Factory method pattern is a type of creational pattern. Creational pattern pattern solves problems related to creating. Factory pattern solves two major problem generally faced by developers.
<span id="more-62"></span>
To reduce too many new operator usage
<ol>
	<li>When working on a large software, numerous instances of classes are created continuously at the runtime. The programmer cannot predict what the user is going to do. So at any given time, the programmer doesn&#8217;t know what object is create. For example, To create a new document, the user might click new text document or new spreadsheet document. There would several possibilities about what the user is going to do. So, a factory class is assigned to do all  these repetitive work of creating a new instance of what the user wants. By separating these repetitive object creations into a factory class, when new classes are added, only the factory class need to be updated.</li>
	<li>To create object without knowing its class name.
When using the concrete classes, the developer has to remember the class names. In factory pattern, choosing what type of object to be created is delegated to the factory class. Usually this is done by sending a parameter. Based on the parameter passed to the factory, the factory creates an instance of a certain type/class.</li>
</ol>
<a href="http://thupten.feedback/wp-content/uploads/2010/06/factorypattern.gif"><img class="alignnone size-medium wp-image-65" title="factorypattern" src="http://thupten.feedback/wp-content/uploads/2010/06/factorypattern-300x151.gif" alt="" width="300" height="151" /></a>

Here is the pseudo code.
<pre name="code" class="java">
public final class DocumentFactory {
   XDocument document;
   XDocument getDocument(String type){
      if(type.equals("text"){
         document = new TextDocument();
      }
      else if(type.equals("sheet"){
         document = new SpreadSheet();
      }
   return document;
   }
}</pre>
<pre name="code" class="java">
public interface XDocument{
   open();
}</pre>
<pre name="code" class="java">
public class TextDocument implements XDocument{
   //concrete class for Text documents
   open(){
      //method to open text document
      System.out.println("opening a text document...");
   }
}</pre>
<pre name="code" class="java">
public class SpreadSheet implements XDocument{
   //concrete class for spreadsheet documents
   open(){
      //method to open spreadsheet document
      System.out.println("opening a spreadsheet document...");
   }
}</pre>
<pre name="code" class="java">
class DocumentProgram{
   public static void main(String[] args){
   //this just created an instance of TextDocument without knowing its class name.
   XDocument doc = df.getDocument("text");
   doc.open();
   }
}</pre>]]></content:encoded>
			<wfw:commentRss>https://www.thupten.feedback/2010/06/09/factory-method-design-pattern/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>
