我应该如何命名java.util.Map? [英] How should I name a java.util.Map?

查看:982
本文介绍了我应该如何命名java.util.Map?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个java.util.Map,它可以从逻辑名称映射到与该名称一起使用的一组参数.

I have a java.util.Map that maps from a logical name to a set of parameters to use with that name.

Map<String,Parameters> howShouldINameThee = ...;

此地图的最佳名称是什么?

What is the best name for this map?

我是否应该简单地将其命名为parametersparametersMap?

Should I go simple and just call this parameters or parametersMap?

我是否在名称中包含有关密钥的信息,例如paramtersByName,以便更清楚地使用String密钥?

Do I include information about the key in the name like paramtersByName so that how to use the String key is more obvious?

推荐答案

地图"将映射到其他映射.
我喜欢使用uidToPerson之类的名称. 到"是我可以想到的最短的明确方法,可以证明我有一张地图.

A Map maps something to something else.
I like to use names like uidToPerson. "To" being the shortest unambiguous way I can think of to show that I have a map.


我还要补充一点,我更喜欢用这种方式命名地图,因为键"和值"在名称中按该顺序出现.与valueByKey相反.在映射操作中,密钥位于第一位.您put(key, value)get(key)给出了一个值.


I'll add that I prefer to have the map named this way, because "key" and "value" appear in that order in the name. As opposed to valueByKey. In mapping operations, the key comes first. You put(key, value) or get(key) that gives a value.

这当然是个人喜好问题.

Of course this is a matter of personal preference.

这篇关于我应该如何命名java.util.Map?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆