コレクションのおかげで、クラスの単一のインスタンスで十分な状況が時々思いつきます。例は私の Decoder クラスです:
public class Decoder
{
private static final Decoder instance = new Decoder();
private final HashMap<Client, State> states = new HashMap<Client, State>();
private Decoder()
{
}
public Packet decode(Client client, ByteBuffer data)
{
return null;
}
}
しかし、私は考えていました。
public class Decoder
{
private static final HashMap<Client, State> states = new HashMap<Client, State>();
public static Packet decode(Client client, ByteBuffer data)
{
return null;
}
}
どちらの設計でも、効果的に同じことを達成できます。2つに実際的な違いはありますか?いつどちらを使用するのですか?ありがとう。