In this task, you must write the EffectFactory class that creates, caches, and returns Effect instances for a given EffectType argument. Make sure your factory creates only one concrete Effect instance for any specific EffectType.
Flyweight
Flyweight factory
Report a typo
Write a program in Java 17
import java.util.Arrays;
import java.util.List;
import java.util.Scanner;
import java.util.Map;
import java.util.HashMap;
class EffectFactory {
// write your code here
public Effect getEffect(EffectType type) {
// write your code here
}
}
enum EffectType { SMOKE, FIRE, BLUR }
interface Effect {
void render();
}
class SmokeEffect implements Effect {
@Override
public void render() {
System.out.println("Renders smoke");
}
}
class FireEffect implements Effect {
@Override
public void render() {
System.out.println("Renders fire");
}
}
___
By continuing, you agree to the JetBrains Academy Terms of Service as well as Hyperskill Terms of Service and Privacy Policy.
Create a free account to access the full topic
By continuing, you agree to the JetBrains Academy Terms of Service as well as Hyperskill Terms of Service and Privacy Policy.