Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

[Java] [Singleton Factory] The singleton pattern by itself is useful but it is really powerful is in combining it with other patterns. Let's assume that

[Java] [Singleton Factory]

The singleton pattern by itself is useful but it is really powerful 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, etc.). 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 using the chocolate factory). If the factory is implemented as a singleton we can avoid this problem.

Implement a singleton factory (from incomplete code) to create different types of chocolate bars with a unique ID. (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.

incomplete code: drive.google.com/drive/folders/1X7JU7z4z1tfp8Ogy8U5SB5LO5JpNjeFs?usp=sharing

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

Students also viewed these Databases questions

Question

1. Describe the factors that lead to productive conflict

Answered: 1 week ago