2 * ============LICENSE_START=======================================================
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
11 * http://www.apache.org/licenses/LICENSE-2.0
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=========================================================
21 package org.openecomp.core.factory.api;
23 import org.openecomp.core.factory.impl.AbstractFactoryBase;
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.
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:
35 * AbstractFactory<IUnknown>
38 * Application code ----> ConcreteFactory
41 * +---------+---------+
43 * BaselineFactoryImpl CustomFactoryImpl
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:
53 * public abstract class ConcreteFactory extends AbstractFactory<IUnknown> {
55 * registerFactory(ConcreteFactory.class, BaselineFactoryImpl.class);
57 * public static ConcreteFactory getInstance() {
58 * return AbstractFactory.<IUnknown, ConcreteFactory.class>getInstance(ConcreteFactory.class);
63 * @param <I> Java interface type created by the factory.
65 public abstract class AbstractFactory<I> extends AbstractFactoryBase {
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.
77 * @return Implementor of the exposed Java interface.
79 public abstract I createInterface();