java - How to encapsulate a Map into a custom object -
My coworker tells me that it is lazy to use sloppy, and that many times the purpose of the programmer will be to provide better service through a real object. But I do not know the best way to do this. This fact is even more complex (me) that the key is an enum type.
Say I have a hashmap
MyEnum
). MyObj
Hashp Value is the latest of many MyObjs in a database, which contains the enum values given.
My best estimate includes an object with four fields, or two arrays with keys and values in sequence.
Obviously whether it is clear or not (this is 5 PM on Thursday = I'm brain-dead), so if necessary, please ask for clarification. Although there is nothing wrong in using the map for your desired purpose, the map is sometimes incorrect, Type objects
string firstname = (string) myMap.get ("first_name"); Unlike
... ...
string first name = person.getFirstName ();
Because Java classes implement AIIMS, you may want to consider putting that value which you are looking directly in your enum class:
< Pre> MyEnum val = getVal (); My obz = vow Getrest Reese My Obze ();
But I want to focus on separating the concerns for deciding whether this really makes sense or not. It may well be that the map for this job is a suitable device.