P*P 发帖数: 36 | 1 在写一个class,要return三个参数,我现在是把三个参数放到map里,然后return map.不
知道这样做好不好?还是我应该把三个参数做成object,然后return那个object? |
k***r 发帖数: 4260 | 2 map needs a lot of memory. a simple class is cheap :)
【在 P*P 的大作中提到】 : 在写一个class,要return三个参数,我现在是把三个参数放到map里,然后return map.不 : 知道这样做好不好?还是我应该把三个参数做成object,然后return那个object?
|
P*P 发帖数: 36 | 3 多谢.
三个参数是string, long and boolean. 或者我把三个参数concatenate成一个string,
用的时候再分解?
【在 k***r 的大作中提到】 : map needs a lot of memory. a simple class is cheap :)
|
l****u 发帖数: 2166 | 4 i vot 4 object
【在 P*P 的大作中提到】 : 在写一个class,要return三个参数,我现在是把三个参数放到map里,然后return map.不 : 知道这样做好不好?还是我应该把三个参数做成object,然后return那个object?
|
g*****g 发帖数: 34805 | 5 Martin Fowler will 2nd that.
【在 l****u 的大作中提到】 : i vot 4 object
|
S*********t 发帖数: 78 | 6 who is martin
【在 g*****g 的大作中提到】 : Martin Fowler will 2nd that.
|
l****u 发帖数: 2166 | 7 a java highhand, google his name, u will see...
【在 S*********t 的大作中提到】 : who is martin
|
l****u 发帖数: 2166 | 8 define an object would be much easier for maintain,
easy to understand.
also easy to unit test.
string,
【在 P*P 的大作中提到】 : 多谢. : 三个参数是string, long and boolean. 或者我把三个参数concatenate成一个string, : 用的时候再分解?
|
k***r 发帖数: 4260 | 9 No. Just define an inner class. new it, and return it.
string,
【在 P*P 的大作中提到】 : 多谢. : 三个参数是string, long and boolean. 或者我把三个参数concatenate成一个string, : 用的时候再分解?
|
c********g 发帖数: 449 | 10 store them into a vector and return it. |
|
|
Z****e 发帖数: 2999 | 11 never liked the idea of storing heterogeneous data in a vector, or
collections alike
【在 c********g 的大作中提到】 : store them into a vector and return it.
|
S*********t 发帖数: 78 | 12 agree.
not a good idea using vector.
also not fancy inner class idea.
【在 Z****e 的大作中提到】 : never liked the idea of storing heterogeneous data in a vector, or : collections alike
|
g*****g 发帖数: 34805 | 13 It depends on how the data object is coupled with the function class.
If the data doesn't make sense out of functional class context,
using inner class is a good pattern.
【在 S*********t 的大作中提到】 : agree. : not a good idea using vector. : also not fancy inner class idea.
|
h**j 发帖数: 2033 | 14 of coz type
【在 P*P 的大作中提到】 : 在写一个class,要return三个参数,我现在是把三个参数放到map里,然后return map.不 : 知道这样做好不好?还是我应该把三个参数做成object,然后return那个object?
|
F****n 发帖数: 3271 | 15 Using Map is not uncommon. You can use LinkedHashMap for small number of
objects.
【在 Z****e 的大作中提到】 : never liked the idea of storing heterogeneous data in a vector, or : collections alike
|
b******y 发帖数: 9224 | 16 object is better, it is easier to see what's returned. |
k***r 发帖数: 4260 | 17 maps has poorer memory efficiency. java is already bad in terms of memory usage. Don't
make it worse :) |
I*******o 发帖数: 53 | 18 can u describe what does this method (class?????) do?
【在 P*P 的大作中提到】 : 在写一个class,要return三个参数,我现在是把三个参数放到map里,然后return map.不 : 知道这样做好不好?还是我应该把三个参数做成object,然后return那个object?
|
n******8 发帖数: 172 | 19 sounds a method that return 3 types of parameters. Why do you not use 3
public unique class variables that you can access from anywhere? |
t*******e 发帖数: 684 | 20
Thread safety will be an issue if he follows your suggestion.
The question is about static data typing (a data object) or dynamic data
typing (a Map, or List, or Collection). Static typing is always preferred
unless the data types may evolve in the future upon business requirements.
【在 n******8 的大作中提到】 : sounds a method that return 3 types of parameters. Why do you not use 3 : public unique class variables that you can access from anywhere?
|
m******t 发帖数: 2416 | 21
I don't know which part is scarier - "public" or "class".
I do like "unique" though. At least we are not going to
try and pad 3 parameters into one single string.
【在 n******8 的大作中提到】 : sounds a method that return 3 types of parameters. Why do you not use 3 : public unique class variables that you can access from anywhere?
|