Why can we not just call the sun.getInstance() directly from Solution class?
package com.codegym.task.task15.task1522;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
/*
Reinforce the singleton pattern
public class SingletonClass {
private static SingletonClass SINGLE_INSTANCE = null;
private SingletonClass() {}
public static SingletonClass getInstance() {
if (SINGLE_INSTANCE == null) {
synchronized(SingletonClass.class) {
SINGLE_INSTANCE = new SingletonClass();
}
}
return SINGLE_INSTANCE;
}
}
*/
public class Solution {
public static void main(String[] args) {
}
public static Planet thePlanet;
// Add static block here
static
{
readKeyFromConsoleAndInitPlanet();
}
public static void readKeyFromConsoleAndInitPlanet() {
// Implement step #5 here
try {
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
String s = reader.readLine();
if(s.equals("sun")) Sun.getInstance();
if(s.equals("moon")) Moon.getInstance();
if(s.equals("earth")) Earth.getInstance();
}
catch (IOException e)
{
System.out.println(e);
}
}
}