I've been reading Clean Code by Robert C. Martin, and came across the infamous statement:
Avoid words like Manager, Processor, Data, or Info in the name of a
class.
So, naturally, I've tried to factor -Info
out of one of my class names. Now, I've seen all sorts of StackOverflow questions asking about what to do to in the case of -Manager
or -Processor
. I've seen comments suggesting that they can't think of a time when -Data
would be a good class name. Well, in my opinion, -Data
and -Info
seem harder to factor out. Especially, for example in the below class.
I have a Server
class like the following:
public class Server {
//What I would call ServerInfo
private int id;
private String name;
private String address;
private int port;
private int connections;
private int maxConnections;
private int status;
//Bunch of members that aren't ServerInfo, for example:
private ConcurrentHashMap<String, File> files = new ConcurrentHashMap<String, File>();
private List<String> filePaths = new List<String>();
/* ... */
public void start() { /* ... */ }
public void stop() { /* ... */ }
}
There is a HashMap
stored of these Server's information like the following on another remote server:
public class ServerMap {
ConcurrentHashMap<Integer, Server> serverMap = /* ... */;
}
But, this HashMap
only needs to know about what I have said is ServerInfo
above. It doesn't need to waste memory by storing a bunch of variables it will never use. So, a Data class is needed to house these variables.
public class ServerInfo {
private int id;
private String name;
private String address;
private int port;
private int connections;
private int maxConnections;
private int status;
}
And ServerMap
now becomes ConcurrentHashMap<Integer, ServerInfo>
.
The problem is that this obviously violates the rule from Clean Code. I could change -Info
to some synonym, but then, isn't that not really fixing the problem? For example, I could call it ServerDetails
but I fail to see how that is any different than ServerData
or ServerInfo
.
I could redefine Server
in a different namespace, and give it just these members, but that seems even more confusing.
What is the best practice solution to this?