In this video, learn how introducing hierarchies into an application can make the Factory Method pattern more complicated. See how code becomes harder to maintain before the complete Factory Method is implemented.
The Factory method pattern gets more complicated…when further hierarchies are introduced.…A more complete version of the Factory method…helps with this by allowing subclasses…to decide which concrete type to return.…This example is a more complete version…of the Candy Store application.…In this example there is still a class called…Candy Store, which gets packages of candy to sell.…In reality there would probably be…a lot more different types of candy…than just chocolates and hard candy.…In fact, chocolates and hard candy are actually…whole sections of the store rather than products.…
Now there are several different types of chocolate:…dark chocolates, milk chocolates, and white chocolates.…There are also three different types of hard candy:…candy canes, lollipops, and peppermints.…All of these different types extends the Candy class…and overrides the makeCandyPackage method.…The candy that is in the hard candy sections…prints out a slightly different message.…Hard candy has to be packaged in quantities of 10,…
Released
8/29/2018- What are creational design patterns?
- Avoid complex constructors
- Implementing the Builder pattern
- Multithreading with the Singleton pattern
- Using the Prototype pattern
- Implementing a simple Factory Method pattern
- Making code more flexible with the Abstract Factory pattern
Share this video
Embed this video
Video: Introduction to hierarchies