0

Is this data structure a bad design choice somehow? Basically every map is a user, which has a bunch of different kinds of fields. Every kind of field is a key in the map, and has a List of the fields(ControlTemplate) that are of that kind.

 protected ArrayList<Map<String, List<ControlTemplate>>> doInBackground(Void... params)
{
     .
     .
     .
}
Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
Rickard
  • 1,289
  • 1
  • 17
  • 27
  • 3
    Why wouldn't you make a `User` class? – Dave Newton May 23 '13 at 13:02
  • 1
    This is what a person with background in dynamic languages would write. It is not good Java style and if you pursue it, you'll be facing new problems each day. – Marko Topolnik May 23 '13 at 13:03
  • In any case, you could drop `ArrayList` at the start in favour of `List`. – vikingsteve May 23 '13 at 13:04
  • 1
    Yes, it's a bad design. It's basically another case of [object denial](http://stackoverflow.com/a/3725728/40342). – Joachim Sauer May 23 '13 at 13:07
  • After all those denials: it would make sense if you do *nothing* with the fields; no suddenly conversion/casting and retrieving values. A generic bean utility, code generator or so. Some extended collection classes (MultiSet or so) certainly would make sense, if not abstraction of an own class. That `doInBackground` is an odd description reminding me of my time sheets. – Joop Eggen May 23 '13 at 13:13

2 Answers2

8

It would be better if you create a User class. And if it is not absolutely necessary you should make an attribute for each property of the user instead of using a map.

Jimmy T.
  • 4,033
  • 2
  • 22
  • 38
  • A User class will be good, however the map is probably necessary to keep. The size and groups of fields will differ from user to user etc. – Rickard May 23 '13 at 13:13
  • @Rickard Jimmy answer is correct. What is the problem of creating a `User` class in your project? – DaGLiMiOuX May 23 '13 at 13:16
  • @Rickard Can you give some example fields? – Jimmy T. May 23 '13 at 13:16
  • @Rickard: nothing's wrong with the User class having a Map of attributes internally. – Joachim Sauer May 23 '13 at 14:11
  • @JimmyT. This is an Android app, and the user fields will vary depending on who is using it. For some it might only be name, phone and mail, for others it might include address, family etc. These fields will be grouped differently as well. – Rickard May 23 '13 at 14:14
  • @Rickard What do you mean when you say "grouped differently"? Address has other properties, family other properties...? – DaGLiMiOuX May 23 '13 at 14:20
  • @DaGLiMiOuX In some views only a couple of fields fit, so a group defines what fields those are. Group1 will always be displayed, in search results, profile view etc, while Group2 and Group3 might only be displayed in profile view. And each group is represented by a key and an ArrayList of ControlTemplates. – Rickard May 23 '13 at 14:42
  • @Rickard Wow... I can't follow you, sorry... This is too strange :S I've never developed an application as strange as that one you are working on. – DaGLiMiOuX May 23 '13 at 15:14
  • @DaGLiMiOuX Heh, that's ok, me neither. It's supposed to be the same isntallation for several different customers with different specs. – Rickard May 23 '13 at 15:18
0

One concept of good OOD is encapsulation. That means that you dont't have compley datastructures like your list but classes which whole purpose is to store data and make an abstraction.

Lukas Eichler
  • 5,689
  • 1
  • 24
  • 43