Answered step by step
Verified Expert Solution
Link Copied!

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.

image

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

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Global Strategy

Authors: Mike W. Peng

5th Edition

0357512367, 978-0357512364

More Books

Students also viewed these Programming questions

Question

Which of our faculty members would you like to work with?

Answered: 1 week ago