Factory object or Product object

I am learning more about the factory design pattern and came across the following example from Microsoft (I recoded it in java). Example here

Short version:

  • An abstract Product class

  • A Concrete Product class that extends Product

  • An abstract Factory class

  • A Concrete Factory class that extends Factory

  • An Assembly class

    public class ProductAssembler {
    public void AssembleProduct(Factory factory)
    Product p = factory.getProduct();
    //do something
  • A client

    public static void main(String[] args)
    Factory factory = new ConcreteFactory();
    new ProductAssembler().AssembleProduct(factory);


  • What is the purpose of creating a factory object in the main method instead of a product object, why don't they pass a product object to the assembleproduct method and change that method so it accepts products instead of factories?
  • Is the assembly class also part of the 'client' or not?



assembleProduct() in ProductAssembler doesn't want to deal with instantiating products. So it wants to delegate this to a Factory so that when newer kinds of products are introduced, the existing factory changes (or a new factory is added) but ProductAssembler doesn't need to change. Instead of instantiation, assembleProduct() calls factory.getProduct().

As far as the Factory pattern is concerned, ProductAssembler is the client. But if you look at it from an application perspective, your main() is the client and hence doesn't deal with Product objects.

Need Your Help

Get selected value of <select> using jQuery

jquery html jquery-selectors html.dropdownlistfor

I am trying to get the value of &lt;select&gt; tags which is kind of a simple task. I have done it several time before but it looks wired no to work this time.

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.