<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0">
	<channel>
		<title><![CDATA[JavaRanch: Latest posts for the topic "factory method pattern"]]></title>
		<link>http://www.coderanch.com/forums/t/9/OO-Patterns-UML-Refactoring/factory-method-pattern</link>
		<description><![CDATA[Latest messages posted in the topic "factory method pattern"]]></description>
		<generator>JForum - http://www.jforum.net</generator>
			<item>
				<title>factory method pattern</title>
				<description><![CDATA[i read about the factory method pattern, but i don't find out the advantages. when the system needs to add a new product, it'll add a new factory to create it, and the client will new a new factory class,  what's the difference between this and new a new product directly?<br /> for example, the client is like this:<br /> <pre>   
public class Client{ 
        private Creator creator1,creator2; 
        private Product prod1,prod2; 
        public static void main(String[] args){ 
                creator1 = new ConcreteCreator1(); 
                proc1 = creator1.create(); 
                creator2 = new ConcreteCreator2(); 
                proc2 = creator2.create();         
                //if i need a product3, it will look like this:
                //creator3 = new ConcreteCreator3(); 
                //proc3  = creator3.create(); 
                //it will change the client code,is that obey the &quot;open--closed&quot; principle???
        } 
}     
 </pre><br /> ]]></description>
				<guid isPermaLink="true">http://www.coderanch.com/forums/posts/preList/448690/1996918</guid>
				<link>http://www.coderanch.com/forums/posts/preList/448690/1996918</link>
				<pubDate><![CDATA[Mon, Jun 8 2009 05:49:02 MDT]]></pubDate>
				<author><![CDATA[long meng]]></author>
			</item>
			<item>
				<title>factory method pattern</title>
				<description><![CDATA[You can use creator.create(String type).<br /> <br /> ]]></description>
				<guid isPermaLink="true">http://www.coderanch.com/forums/posts/preList/448690/1996933</guid>
				<link>http://www.coderanch.com/forums/posts/preList/448690/1996933</link>
				<pubDate><![CDATA[Mon, Jun 8 2009 06:17:01 MDT]]></pubDate>
				<author><![CDATA[Kengkaj Sathianpantarit]]></author>
			</item>
			<item>
				<title>factory method pattern</title>
				<description><![CDATA[This looks to me like we are talking about Abstract Factory here, not Factory Method.<br /> <br /> Anyway, the main reason to use an Abstract Factory is when you want to decouple the decision on *what* exactly to create, and *when* (or *how many* instances) to create.<br /> <br /> So, typically, the client who calls the create method will *not* also instantiate the factory. The factory will be created outside and passed into the client (for example via Dependency Injection).<br /> <br /> Does that help?]]></description>
				<guid isPermaLink="true">http://www.coderanch.com/forums/posts/preList/448690/1997167</guid>
				<link>http://www.coderanch.com/forums/posts/preList/448690/1997167</link>
				<pubDate><![CDATA[Mon, Jun 8 2009 11:48:37 MDT]]></pubDate>
				<author><![CDATA[Ilja Preuss]]></author>
			</item>
			<item>
				<title>factory method pattern</title>
				<description><![CDATA[<blockquote class="uncited">
			<div> This looks to me like we are talking about Abstract Factory here, not Factory Method. <br /> <br /> Anyway, the main reason to use an Abstract Factory is when you want to decouple the decision on *what* exactly to create, and *when* (or *how many* instances) to create. <br /> <br /> So, typically, the client who calls the create method will *not* also instantiate the factory. The factory will be created outside and passed into the client (for example via Dependency Injection). <br /> <br /> Does that help?    </div>
		</blockquote><br /> <br /> so the main() in the client should in another class, and the Client get everything(factory and product) ready, in the main(), just new a client, and call its method, is that right?]]></description>
				<guid isPermaLink="true">http://www.coderanch.com/forums/posts/preList/448690/1997371</guid>
				<link>http://www.coderanch.com/forums/posts/preList/448690/1997371</link>
				<pubDate><![CDATA[Mon, Jun 8 2009 20:41:51 MDT]]></pubDate>
				<author><![CDATA[long meng]]></author>
			</item>
			<item>
				<title>factory method pattern</title>
				<description><![CDATA[<blockquote>
			<div>
				<cite>Ilja Preuss wrote:</cite>This looks to me like we are talking about Abstract Factory here, not Factory Method.</div>
		</blockquote><br /> I don't think so. Abstract Factory is used for create "families" of product. It seems that many people don't understand Abstract Factory, "families" is a key.<br /> <br /> Structure from GoF:<br /> <br /> <pre>interface AbstractFactory {
   AbstractProductA createProductA();
   AbstractProductB createProductB();
}

ConcreteFactory1 implements AbstractFactory {
   ...
}

interface AbstractProductA {
}

ProductA1 implements AbstractProductA {
}

ProductA2 implements AbstractProductA {
}

interface AbstractProductB {
}

ProductB1 implements AbstractProductB {
}

ProductB2 implements AbstractProductB {
}</pre><br /> [Edited code]]]></description>
				<guid isPermaLink="true">http://www.coderanch.com/forums/posts/preList/448690/1997497</guid>
				<link>http://www.coderanch.com/forums/posts/preList/448690/1997497</link>
				<pubDate><![CDATA[Tue, Jun 9 2009 01:20:02 MDT]]></pubDate>
				<author><![CDATA[Kengkaj Sathianpantarit]]></author>
			</item>
			<item>
				<title>factory method pattern</title>
				<description><![CDATA[so anyone tell me the advantages of factory method pattern, thanks]]></description>
				<guid isPermaLink="true">http://www.coderanch.com/forums/posts/preList/448690/1998068</guid>
				<link>http://www.coderanch.com/forums/posts/preList/448690/1998068</link>
				<pubDate><![CDATA[Tue, Jun 9 2009 19:10:09 MDT]]></pubDate>
				<author><![CDATA[long meng]]></author>
			</item>
			<item>
				<title>factory method pattern</title>
				<description><![CDATA[<pre>public class Client{    
        private Creator creator1,creator2;    
        private Product prod1,prod2;    
        public static void main(String[] args){    
                creator1 = new ConcreteCreator1();    
                proc1 = creator1.create();    
                creator2 = new ConcreteCreator2();    
                proc2 = creator2.create();            
                //if i need a product3, it will look like this:   
                //creator3 = new ConcreteCreator3();    
                //proc3  = creator3.create();    
                //it will change the client code,is that obey the &quot;open--closed&quot; principle???   
        }    
}  </pre>     <br /> <br /> This is not a good example to demonstrate the benefits of the Factory Method design pattern.<br /> <br /> To get a good unstanding of the benefits you will need to know a few other things like delegation, syntax-level dependencies, interfaces, low coupling, etc.<br /> <br /> The primary benefit is that client objects should not have to be re-compiled and re-tested everytime a new class is created. The ultimate goal is <b>extensibility </b>and <b>rapid development</b>. A clear understanding of what these terms mean will also be required.<br /> <br /> Good luck! <br />  ]]></description>
				<guid isPermaLink="true">http://www.coderanch.com/forums/posts/preList/448690/1998118</guid>
				<link>http://www.coderanch.com/forums/posts/preList/448690/1998118</link>
				<pubDate><![CDATA[Tue, Jun 9 2009 21:11:58 MDT]]></pubDate>
				<author><![CDATA[Dave Clarks]]></author>
			</item>
			<item>
				<title>factory method pattern</title>
				<description><![CDATA[there is always a place to new the new factory, why i can't just new the new product instead of the new factory?]]></description>
				<guid isPermaLink="true">http://www.coderanch.com/forums/posts/preList/448690/1998197</guid>
				<link>http://www.coderanch.com/forums/posts/preList/448690/1998197</link>
				<pubDate><![CDATA[Wed, Jun 10 2009 00:17:39 MDT]]></pubDate>
				<author><![CDATA[long meng]]></author>
			</item>
			<item>
				<title>factory method pattern</title>
				<description><![CDATA[You are missing the point of "not changing the client object code." <br /> <br /> The classes of client objects which use the "factory method" do not need to be renamed, recompiled, newed or whatever.<br /> <br /> Keep in mind that object-oriented design patterns are typically for solving significant issues with large systems. It might be hard to learn or understand if using "small" examples with only a few classes. If your implementation of Factory Method saves you time because you do not need to modify 20 to 50 classes, then this is a significant benefit.]]></description>
				<guid isPermaLink="true">http://www.coderanch.com/forums/posts/preList/448690/1998480</guid>
				<link>http://www.coderanch.com/forums/posts/preList/448690/1998480</link>
				<pubDate><![CDATA[Wed, Jun 10 2009 07:16:59 MDT]]></pubDate>
				<author><![CDATA[Dave Clarks]]></author>
			</item>
			<item>
				<title>factory method pattern</title>
				<description><![CDATA[<blockquote>
			<div>
				<cite>James Clark wrote:</cite>You are missing the point of <b>"not changing the client object code." </b><br /> <br /> The classes of client objects which use the "factory method" do not need to be renamed, recompiled, newed or whatever.<br /> <br /> Keep in mind that object-oriented design patterns are typically for solving significant issues with large systems. It might be hard to learn or understand if using "small" examples with only a few classes. If your implementation of Factory Method saves you time because you do not need to modify 20 to 50 classes, then this is a significant benefit.</div>
		</blockquote><br /> <br /> i do  remember  the point, like my code: if there is a new product the Client class want to use , how to do it without change the code?<br /> <br /> i'm realy confused, hope you can help me ! thank you very much!!!]]></description>
				<guid isPermaLink="true">http://www.coderanch.com/forums/posts/preList/448690/1998509</guid>
				<link>http://www.coderanch.com/forums/posts/preList/448690/1998509</link>
				<pubDate><![CDATA[Wed, Jun 10 2009 08:01:49 MDT]]></pubDate>
				<author><![CDATA[long meng]]></author>
			</item>
			<item>
				<title>factory method pattern</title>
				<description><![CDATA[<pre>public final class SomeClientObject {

    ...
    public final int doSomeCalculationWithProduct() {
         ...
         Product _p = obj.getProduct(x);
         
         // do stuff here with Product object

         return y;       
    
    }
    ...

}</pre><br /> <br /> getProduct() is the factory method. The code that creates Product objects is in the class of 'obj'. The actual class name of the type of Product<br /> does not exist in the client object. The call to "new" is not in the client object. The client object does not contain any syntax-level dependencies upon Product objects and you will not have to recompile the client object class if you change the name of the Product implementations or add new Product types.<br /> <br /> The client object indicates which Product he/she wants using the variable x.<br /> <br /> <pre>public interface Product {

}


public final class XYX implements Product {


}

public final class IntCLTR implements Product {


}

public final class Uredd implements Product {


}

public final class RanchIUY implements Product {


}

public final class SmilTREpl implements Product {


}


</pre><br /> ]]></description>
				<guid isPermaLink="true">http://www.coderanch.com/forums/posts/preList/448690/1998540</guid>
				<link>http://www.coderanch.com/forums/posts/preList/448690/1998540</link>
				<pubDate><![CDATA[Wed, Jun 10 2009 08:42:55 MDT]]></pubDate>
				<author><![CDATA[Dave Clarks]]></author>
			</item>
			<item>
				<title>factory method pattern</title>
				<description><![CDATA[thanks James! i got it~!<br /> and a little question here is where the SomeClientObject  class get the factory object ?<br /> shall i make it an instance varible, and use setter method to assign the concrete factory object to it?<br /> ]]></description>
				<guid isPermaLink="true">http://www.coderanch.com/forums/posts/preList/448690/1998843</guid>
				<link>http://www.coderanch.com/forums/posts/preList/448690/1998843</link>
				<pubDate><![CDATA[Wed, Jun 10 2009 19:55:39 MDT]]></pubDate>
				<author><![CDATA[long meng]]></author>
			</item>
			<item>
				<title>factory method pattern</title>
				<description><![CDATA[Great! <br /> <br /> Experiment a little bit and try a few different ways. See which one you think is best and compare it to the others. This is an effective way to learn. There are no specific rules to implementing design patterns. You need to do it the best way for your application. When you have implemented a pattern three or four times, you will know what works well and what does not work well. Good luck!]]></description>
				<guid isPermaLink="true">http://www.coderanch.com/forums/posts/preList/448690/1998854</guid>
				<link>http://www.coderanch.com/forums/posts/preList/448690/1998854</link>
				<pubDate><![CDATA[Wed, Jun 10 2009 20:49:41 MDT]]></pubDate>
				<author><![CDATA[Dave Clarks]]></author>
			</item>
			<item>
				<title>factory method pattern</title>
				<description><![CDATA[<blockquote>
			<div>
				<cite>long meng wrote:</cite><br /> and a little question here is where the SomeClientObject  class get the factory object ?<br /> shall i make it an instance varible, and use setter method to assign the concrete factory object to it?<br /> </div>
		</blockquote><br /> For factory method pattern, don't call the creator "factory object", call it creator because it can have other responsibility.<br /> When using Design Patterns, you should program to interface, Creator should be an interface (or at least an abstract class).<br /> Client code will have dependency to interface, not concrete class.]]></description>
				<guid isPermaLink="true">http://www.coderanch.com/forums/posts/preList/448690/1998872</guid>
				<link>http://www.coderanch.com/forums/posts/preList/448690/1998872</link>
				<pubDate><![CDATA[Wed, Jun 10 2009 22:07:50 MDT]]></pubDate>
				<author><![CDATA[Kengkaj Sathianpantarit]]></author>
			</item>
	</channel>
</rss>
