View Javadoc

1   //----------------------------------------------------------------------
2   // 
3   // PerfectJPattern: "Design patterns are good but components are better!" 
4   // IFactoryMethod.java Copyright (c) 2009 Giovanni Azua Garcia
5   // bravegag@hotmail.com
6   //  
7   // This program is free software; you can redistribute it and/or
8   // modify it under the terms of the GNU General Public License
9   // as published by the Free Software Foundation; either version 3
10  // of the License, or (at your option) any later version.
11  //
12  // This program is distributed in the hope that it will be useful,
13  // but WITHOUT ANY WARRANTY; without even the implied warranty of
14  // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  // GNU General Public License for more details.
16  //
17  // You should have received a copy of the GNU General Public License
18  // along with this program; if not, see <http://www.gnu.org/licenses/>.
19  //
20  //----------------------------------------------------------------------
21  package org.perfectjpattern.core.api.creational.factorymethod;
22  
23  /**
24   * <b>Factory Method Design Pattern</b>: Define an interface for creating an
25   * object, but let subclasses decide which class to instantiate. 
26   * Factory Method lets a class defer instantiation to subclasses.
27   * (Gamma et al, Design Patterns)
28   * <br/><br/>
29   * 
30   * <b>Responsibility</b> Abstract definition of the "Creator": <br/>
31   * <br/>
32   * <ul>
33   * <li>Declares the factory method, which returns an object of type 
34   * Product.</li> 
35   * <li>Creator may also define a default implementation of the factory 
36   * method that returns a default ConcreteProduct object.
37   * may call the factory method to create a Product object.</li>
38   * </ul>
39   * 
40   * <br/>
41   * Example usage:
42   * <pre><code>
43   * import org.perfectjpattern.core.api.creational.factorymethod.*;
44   *       
45   *  //
46   *  // Example of Factory Method subtype that creates Product with a
47   *  // name parameter. 
48   *  //
49   *  public IProductFactory
50   *  extends IFactoryMethod&lt;Product&gt;
51   *  {
52   *      //--------------------------------------------------------------------
53   *      // public
54   *      //--------------------------------------------------------------------
55   *      public void
56   *      setName(String aName);          
57   *  } 
58   * 
59   * </code></pre>
60   * @param <T> Type of elements created.
61   * 
62   * @author <a href="mailto:bravegag@hotmail.com">Giovanni Azua</a>
63   * @version $Revision: 1.0 $ $Date: Jun 19, 2007 11:01:51 PM $
64   */
65  public 
66  interface IFactoryMethod<T>
67  {
68      //------------------------------------------------------------------------
69      // public
70      //------------------------------------------------------------------------
71      /**
72       * Returns newly created instance
73       * 
74       * @return Newly created instance
75       */
76      T create();    
77  }