Merging of TOSCA Cloud Topology Templates - IAAS
Merging of TOSCA Cloud Topology Templates - IAAS
Merging of TOSCA Cloud Topology Templates - IAAS
You also want an ePaper? Increase the reach of your titles
YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.
2 Fundamentals<br />
class Factory Method<br />
«abstract»<br />
Product<br />
+ operation() : void<br />
«abstract»<br />
Factory<br />
+ factoryMethod() : Product<br />
ConcreteProduct<br />
+ operation() : void<br />
ConcreteFactory<br />
+ factoryMethod() : Product<br />
return<br />
new ConcreteProduct()<br />
Fig. 2.3: Factory Method design pattern 6<br />
In the following Listing 2.5, Listing 2.6, Listing 2.7 and Listing 2.8 provide a simple continuous<br />
example <strong>of</strong> the usage <strong>of</strong> the Factory Method.<br />
Abstract Factory using the Factory Method<br />
1<br />
2<br />
3<br />
public abstract class Factory {<br />
}<br />
public abstract Product createProduct();<br />
Listing 2.5: Code example <strong>of</strong> abstract factory class <strong>of</strong> the Factory Method design pattern<br />
The abstract class Factory in Listing 2.5 shows the aforementioned abstract factory that defines<br />
an abstract factoryMethod to create a new instance <strong>of</strong> a class implementing a particular<br />
interface, in this case the abstract class Product not depicted here but being the same as<br />
in Fig. 2.3. A concrete implementation <strong>of</strong> the abstract factory class is shown in Listing 2.6.<br />
The class overrides the createProduct factory method and returns an instance <strong>of</strong> the ConcreteProduct<br />
class from Fig. 2.3. The choice <strong>of</strong> the specific factory must take place only once,<br />
e.g. in an initialization method <strong>of</strong> the framework as depicted in Listing 2.7. In the rest <strong>of</strong> the<br />
code the factory creates instances by utilizing polymorphism without knowing the exact<br />
type <strong>of</strong> Product.<br />
6 Adopted from [15]<br />
19