Question
implement the Cake problem the Factory Method pattern. Cake is the abstract class, all different cake classes inherit from this class. Cake class has three
implement the Cake problem the Factory Method pattern. Cake is the abstract class, all different cake classes inherit from this class. Cake class has three properties; name of the cake, type of the cake (whether cake contains butter or it is butter less) and the last one is price. The class Cake has two abstract methods:
void recipe() void comments()
It also has another public method called aboutCake( ). The method provides the name and the price of the cakes and the comments about the cake.
Create three subclasses from the class Cake. Encapsulating Object Creation
You are going to define a factory interface and a concrete factory class (CakeFactory) that implements factory interface which will encapsulate the object creation code for different types of cakes.
public interface Factory { Cake createCake(String cakeName); }
public class CakeFactory implements Factory { public Cake createCake(String cakeName) { ........... }
Create a class Test to test the class CakeFactory.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started