Complete the code to declare the Factory Method in the Creator class.
abstract class Creator { abstract [1] createProduct(); }
The Factory Method returns a Product type object, so the return type must be Product.
Complete the code to implement the Factory Method in the ConcreteCreator class.
class ConcreteCreator extends Creator { @Override public [1] createProduct() { return new ConcreteProduct(); } }
The method must return the abstract type Product to follow the Factory Method pattern, even if it returns a ConcreteProduct instance.
Fix the error in the client code that uses the Factory Method to get a product.
Creator creator = new ConcreteCreator();
Product product = creator.[1]();
product.use();The Factory Method is named createProduct in the Creator class, so the client must call this method.
Fill both blanks to complete the product interface and its concrete implementation.
interface [1] { void [2](); } class ConcreteProduct implements Product { public void use() { System.out.println("Using ConcreteProduct"); } }
The interface is named Product and declares the method use() which the concrete class implements.
Fill all three blanks to complete the Creator class with a factory method and a business logic method.
abstract class Creator { public abstract [1] createProduct(); public void [2]() { [3] product = createProduct(); product.use(); } }
The factory method returns a Product. The business method is named operate and it calls createProduct() to get a product and use it.