java - Is using one class to store data safe? -
so searching storing data in 1 class, , found this. however, that's not i'm looking for. wanted know whether it's bad practice, can cause performance issues in application, or if there's way it, etc... (and i'm not doing on android).
let's have class stores hashmap<enum, object>
, initialized when create class in main.
public main() { // creates hashmap, initialized in constructor 'memorycontainer' memorycontainer m = new memorycontainer(); m.gettesthash().put(someenum.test, "test"); // using created hashmap }
other casting value every time use it, cause major issues? if so, there alternative?
there's nothing wrong storing static values in class, not practice.
to store constants should create interface
every field in interface constant (public static final).
a better approach store these values in properties files
, , load them needed. properties file can stored externally , person isn't aware of source code able modify properties file if needed. example can store database connection details in properties files , if server support admin determines database instance down, he/she can edit properties file point application new one.
finally flexibility shouldn't store configuration inside application @ all. can stored in database mysql
or in fast data structure storage redis
. allow multiple instances of application share configuration data , allow modify configuration on fly modifying them in database.
sometimes git repository
used store kind of data (like in case of microservices). git repository in addition being shared among instances, maintains history of modifications.
Comments
Post a Comment