Answered step by step
Verified Expert Solution
Question
1 Approved Answer
package com.upgrad.patterns.Service; import com.upgrad.patterns.Interfaces.IndianDiseaseStat; import com.upgrad.patterns.Constants.SourceType; import com.upgrad.patterns.Strategies.DiseaseShStrategy; import com.upgrad.patterns.Strategies.JohnHopkinsStrategy; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; @Service public class IndiaDiseaseStatFactory { private IndianDiseaseStat diseaseShStrategy; private IndianDiseaseStat johnHopkinsStrategy;
package com.upgrad.patterns.Service;
import com.upgrad.patterns.Interfaces.IndianDiseaseStat;
import com.upgrad.patterns.Constants.SourceType;
import com.upgrad.patterns.Strategies.DiseaseShStrategy;
import com.upgrad.patterns.Strategies.JohnHopkinsStrategy;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
@Service
public class IndiaDiseaseStatFactory
private IndianDiseaseStat diseaseShStrategy;
private IndianDiseaseStat johnHopkinsStrategy;
@Autowired
public IndiaDiseaseStatFactoryDiseaseShStrategy diseaseShStrategy, JohnHopkinsStrategy johnHopkinsStrategy
this.diseaseShStrategy diseaseShStrategy;
this.johnHopkinsStrategy johnHopkinsStrategy;
please write the code for this statement
create a method named GetInstance with return type as IndianDiseaseStat and parameter of type sourceType
create a conditional statement
if the sourceType is JohnHopkins
return johnHopkinsStrategy
if the sourceType is DiseaseSh
return diseaseShStrategy
create a message for invalid disease strategysourceType
throw the message as an Illegal argument exception
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