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

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!