Select Page

Abstract factory

Abstract factory

Provide an interface for creating families of related or dependent objects without specifying their concrete classes.

Source Code

/**  * Abstract factory declares an interface for operations that create abstract  * product objects.  *   * @role __Factory  */ public interface AbstractFactory {         /**   * Creates abstract product   */         ProductA createProductA();        /**   * Creates abstract product   */         ProductB createProductB();}  /**  * Abstract factory declares an interface for operations that create abstract  * product objects.  *   * @role __Factory  */ public interface AbstractFactory {         /**   * Creates abstract product   */         ProductA createProductA();        /**   * Creates abstract product   */         ProductB createProductB();}  /**  * Abstract product - an interface for a type of Product object.  *   * @role __Product  * @see AbstractFactory  */ public interface ProductA {          /*   * add product method declarations here   */ }  /**  * Concrete Factory implements operations of AbstractFactory to create Concrete  * product objects.  */ public class MyFactory implements AbstractFactory {          /**   * Creates concrete product ConcreteProduct1   */         public ProductA createProductA() {                 return new ConcreteProduct1();        }          /**   * Creates concrete product ConcreteProduct2   */         public ProductB createProductB() {                 return new ConcreteProduct2();        }  }  /**  * Concrete product defines a product object to be created by the corresponding  * concrete factory.  *   * @see MyFactory  */ public class ConcreteProduct1 implements ProductA {  }  /**  * Concrete product defines a product object to be created by the corresponding  * concrete factory.  *   * @see MyFactory  */ public class ConcreteProduct2 implements ProductB {  } 

About The Author

I worked with various Insurances companies across Switzerland on online applications handling billion premium volumes. I love to continuously spark my creativity in many different and challenging open-source projects fueled by my great passion for innovation and blockchain technology.In my technical role as a senior software engineer and Blockchain consultant, I help to define and implement innovative solutions in the scope of both blockchain and traditional products, solutions, and services. I can support the full spectrum of software development activities, starting from analyzing ideas and business cases and up to the production deployment of the solutions.I'm the Founder and CEO of Disruptr GmbH.

Categories