Question: 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

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

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 Programming Questions!