--> state attribute for a class(int)
---> only one object is allowed for each state. e.g. process information for each process in a UNIX environment.
Aside
HashMap
-A way of storing objects with respect to a key (i.e. an integer)
Objects: a,b,c
HashMap: h
h.put(a, 100) places the object a with the key 100.
-Say I want to store objects of type MyObject with respect to integers.
-HashMap
Singleton-per-state design pattern.
-constructor is private
-private static HashMap stores the instances with respect to status.
-getInstance(int state) is a public static method which checks the HashMap for an instance corresponding to state. If it exists, it is returned, if not, store it in HashMap, return it.
You cannot access non-static attributes from a static method.

No comments:
Post a Comment