push addional code
[sdc.git] / openecomp-be / lib / openecomp-core-lib / openecomp-facade-lib / openecomp-facade-api / src / main / java / org / openecomp / core / factory / api / AbstractFactory.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * SDC
4  * ================================================================================
5  * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6  * ================================================================================
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  * 
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  * 
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  * ============LICENSE_END=========================================================
19  */
20
21 package org.openecomp.core.factory.api;
22
23 import org.openecomp.core.factory.impl.AbstractFactoryBase;
24
25 /**
26  * This class provides generic implementation of an abstract factory. Components exposed as Java
27  * interfaces should have their own concrete factories derived from the given class. This assures
28  * code alignment and consistency across all Service Management components.
29  * The class actually
30  * uses singleton pattern to instantiate and reuse just one instance of a factory. Therefore, each
31  * factory implementation has to be <i>thread-safe</i>.
32  * In a general case, the hierarchy of
33  * factory objects for an Java interface <tt>IUknown</tt> may look as follows:
34  * <pre>
35  *                     AbstractFactory&lt;IUnknown&gt;
36  *                                ^
37  *                                |
38  *   Application code ----> ConcreteFactory
39  *                                ^
40  *                                |
41  *                      +---------+---------+
42  *                      |                   |
43  *             BaselineFactoryImpl   CustomFactoryImpl
44  * </pre>
45  * Where the classes responsibility is: <ul> <li>Abstract factory - common logic to retrieve the
46  * implementation class name from a central repository.</li> <li>Concrete factory - abstract class
47  * that only exposes to application layer the type specific API such as: <ul> <li><tt>public static
48  * ConcreteFactory getInstance()</tt></li> </ul> <li>Baseline factory - out of the box
49  * implementation of concrete factory (that can be replaced by a custom one depending on customer
50  * needs) which actually implements method: <ul> <li><tt>public IUnknown createInterface()</tt></li>
51  * </ul> </ul> The normal concrete factory class may look like:
52  * <pre>
53  * public abstract class ConcreteFactory extends AbstractFactory&lt;IUnknown&gt; {
54  *   static {
55  *     registerFactory(ConcreteFactory.class, BaselineFactoryImpl.class);
56  *   }
57  * public static ConcreteFactory getInstance() {
58  * return AbstractFactory.&lt;IUnknown, ConcreteFactory.class&gt;getInstance(ConcreteFactory.class);
59  *   }
60  * }
61  * </pre>
62  *
63  * @param <I> Java interface type created by the factory.
64  */
65 public abstract class AbstractFactory<I> extends AbstractFactoryBase {
66
67
68   /**
69    * Returns the interface implementor instance.
70    * <b>Note</b>: It's up to the concrete factory to decide on the actual
71    * implementation of the returned interface. Therefore, the call can get the
72    * same instance per each call in case of singleton implementation or new
73    * instance otherwise. However, the API consumer may not assume anything
74    * regarding the underlying logic and has always go through the factory to
75    * obtain the reference.
76    *
77    * @return Implementor of the exposed Java interface.
78    */
79   public abstract I createInterface();
80
81 } // End of class