1 Programming Assignment: Develop a singleton class called ServiceProvider. Incl
ID: 3746506 • Letter: 1
Question
1 Programming Assignment: Develop a singleton class called ServiceProvider. Include in the class a static method called getlnstance) modeled after the lazy initialization technique found in section 26.5 of Larman Have ServiceProvider print "Constructing ServiceProvider" on its first construction and print "ServiceProvider already exists" on subsequent attempts at construction. Have your main) construct ServiceProvider three timeS sequentially using ServiceProvider.getinstance( Create and submit your Eclipse project using the name XXXXSingleton, where XXXX is your last name, e.g., BhattacharyyaSingleton. Insert your name and the assignment number as comments at the beginning of your code 2.Programming Assignment: Design 4 classes MyController to control the execution of the example, ExampleFactory (a singleton) to create a Service object, a Service class interface named IAService a Service class named AService the implements IAService Have MyController construct the ExampleFactory as a singleton as in program 1 Have MyController use the ExampleFactory method getService() to create an instance of AService. Have MyController use the method ProvideService) in AService to print "l'm now providing the service for MyController"Explanation / Answer
Given below is the code for the question 1. As per Chegg policy we are supposed to answer the first questoin. So request you to post the other question separately.
Replace the XXXX in the code with your last name.
To indent code in eclipse , select code by pressing ctrl+a and then indent using ctrl+i
public class XXXXSerivceProvider {
private static XXXXSerivceProvider instance = null;
public static XXXXSerivceProvider getInstance(){
if(instance == null){
System.out.println("Constructing ServiceProvider");
instance = new XXXXSerivceProvider();
}
else {
System.out.println("ServiceProvider already exists");
}
return instance;
}
public static void main(String[] args) {
XXXXSerivceProvider sp1 = XXXXSerivceProvider.getInstance();
XXXXSerivceProvider sp2 = XXXXSerivceProvider.getInstance();
XXXXSerivceProvider sp3 = XXXXSerivceProvider.getInstance();
}
}
output
-----
Constructin ServiceProvider
ServiceProvider already exists
ServiceProvider already exists
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.