My concept is not clear in this design pattern, i am unable to understand code in the class with main method, i will be thankful if anyone could help me out
Here are some class for a Pizza Factory
I have doubt mainly in the functionality of these lines
Whats the point of passing the factory reference in the PizzaStore constructor. Can't the code run without passing the reference ??
Can't we remove this from the PizzaStore class and write the code in PizzaTestDrive class as
posted 8 years ago
I tried doing that but met with the following error
Exception in thread "main" java.lang.NullPointerException
A factory method is often called before any instances exist. Factory methods are therefore usually made static, and called on the name of the class. In the very iffy, unscientific and misleading Campbell Ritchie classification of methods, factory methods are usually 1368.
What you're seeing here is the separation of concerns - the principle that classes ought to have a single responsibility. Yes, you could put the createPizza logic from SimplePizzaFactory into PizzaStore. And that way PizzaStore wouldn't need to have a factory object passed in. But this design separates the logic of determining which type of pizza to create from the actions that are performed on the pizza to prepare it for delivery.
Where you'd really see the benefit is if the system expanded. Let's say the company opened a pizza restaurant. They'd still want the same logic for selecting a particular sub-type of pizza, but the preparation steps would be different. So you could then create a PizzaRestaurant class and pass it the same SimplePizzaFactory.
Matthew Brown wrote:Where you'd really see the benefit is if the system expanded. Let's say the company opened a pizza restaurant. They'd still want the same logic for selecting a particular sub-type of pizza, but the preparation steps would be different. So you could then create a PizzaRestaurant class and pass it the same SimplePizzaFactory.
and I just had a Pizza in my lunch.. yummy.. and guess whats the factory might get used here, Its IndiaPizzaFactory, they put lots of Paneer on Cheese Pizza
posted 8 years ago
Paneer??? It’s supposed to be mozarella. But I suppose paneer made from buffalo milk would taste similar.
Campbell Ritchie wrote:But I suppose paneer made from buffalo milk would taste similar.
Exactly, Paneer is something that is discovered in India and we Indian can use it with any food. Pizza is no exception..
I think OP have enough idea now, why we need to pass factory object to pizza store. Given a same setup of Domino's (the PizzaStore class), the way pizza are created here in India (IndiaPizzaFactory class) and that in UK (UKPizzaFactory class) is different..
Three ways to do that, and believe it or not, I can make use of the previous silly banter.You can decide whether you like those methods or not. There is something suspect about requiring a cast, so that might want changing. But you can see the design idea, I hope.
It runs on an internal combustion engine. This ad does not:
Sauce Labs - World's Largest Continuous Testing Cloud for Websites and Mobile Apps