Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Task 2: Singleton Factory 1. The singleton pattern by itself is useful but it its really power is in combining it with other patterns.
Task 2: Singleton Factory 1. The singleton pattern by itself is useful but it its really power is in combining it with other patterns. Let's assume that we design an application for the production of different types of chocolate bars (Wonka Bar, Oompaloompa Bar,). Each type of chocolate bar has a unique ID. This unique ID is printed on the inside of the chocolate bar wrapper. Customers can check this ID online on and win a visit to the chocolate factory. Chocolate bars are being mass produced using multiple threads and a problem occurs when the factory is instantiated twice in 2 different threads as it is possible to have 2 overlapping ids for 2 different bars of the same type, which can lead to problems (such as customers suing the chocolate factory). If the factory is implemented as a singleton we can avoid this problem. Implement a "singleton factory" to create different types of chocolate bars with unique id's. (Note different types of chocolate bars can have the same id). Use different threads to produce the bars to check the correctness of you Singleton factory implementation.
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