Redian新闻
>
请教关于使用map和fields
avatar
请教关于使用map和fields# Java - 爪哇娇娃
f*0
1
我有一个class,有好几个fields.
我知道的选择有1) 让这几个fields独立存在。使用getter和setter来修改他们。
2)用一个map,然后通过map的方法来修改相关key的value。
不知道哪个更好?请指教。谢谢。
avatar
g*g
2
In most cases, No.1. Strong typed. No coupling.

【在 f*****0 的大作中提到】
: 我有一个class,有好几个fields.
: 我知道的选择有1) 让这几个fields独立存在。使用getter和setter来修改他们。
: 2)用一个map,然后通过map的方法来修改相关key的value。
: 不知道哪个更好?请指教。谢谢。

avatar
f*0
3
多谢好虫的指点。一语点醒。

【在 g*****g 的大作中提到】
: In most cases, No.1. Strong typed. No coupling.
avatar
s*e
4
I think that you really need a book for ood & oop.
avatar
x*d
5
如果你确定自己对各种数据结构的在map实现很清楚,你可以试试。不过多数高级程序
猿都不敢说对collections/map玩透了。这条过不去,牵涉到各种collections的使用都
要慎重,先别说ood/oop那些道理。
avatar
w*z
6
collections 有啥高深的? guava 的更好用。

【在 x****d 的大作中提到】
: 如果你确定自己对各种数据结构的在map实现很清楚,你可以试试。不过多数高级程序
: 猿都不敢说对collections/map玩透了。这条过不去,牵涉到各种collections的使用都
: 要慎重,先别说ood/oop那些道理。

avatar
f*0
7
多谢指点。
自己是个门外汉,在自学中。虽然读过几本书,但是每次读完,要真正理解一些概念并
且加以应用总是很难。每每都是读过了,过一阵才恍然大悟。高兴之余,却更加彷徨:
说不定自己所谓的悟其实是错的呢。
像xmlxsd所说的,关于“如果你确定自己对各种数据结构的在map实现很清楚,你可以
试试”,自己实在不知道collections和map的高深之处,特别是在我自己的这个程序里
, 不知可否指点一下? 好虫兄给了一个简明扼要的指点,不知xmlxsd可否指点一下?
感激不尽。

【在 s******e 的大作中提到】
: I think that you really need a book for ood & oop.
avatar
s*e
8
Your problem has nothing to do with java colletcions framework. ALso I do
not think java collections framework is 高深. But that is off the topic.
Java is a strong type and object oriented language. you should be able to
find tons of articles and books talking about why an object oriented
language is better than procedural languages for enterprise applications.
Using map to save the heterogeneous class states not only defeats the
purpose of the strong type language, but also fails to mimic the domain
world and thus reduce the chance of class reuse. Also there are other issues
, such as casting, inheritance, and coupling.
I am not saying that you should never do it. In one case, I have used a
class like this as the context bag to pass up objects to a depended modules.
So inside the depending modules, I can write all different handlers to
process those objects at the right moment when the whole process is still in
the upstream module. The only reason that I did that was to create
unidirectional dependency from down stream modules to upstream modules. But
it was a very complicated system. For a novice, I really doubt that you will
need to do it.
avatar
x*d
9
I was off topic. never mind. your problem has nothing to do with collections
.

【在 f*****0 的大作中提到】
: 多谢指点。
: 自己是个门外汉,在自学中。虽然读过几本书,但是每次读完,要真正理解一些概念并
: 且加以应用总是很难。每每都是读过了,过一阵才恍然大悟。高兴之余,却更加彷徨:
: 说不定自己所谓的悟其实是错的呢。
: 像xmlxsd所说的,关于“如果你确定自己对各种数据结构的在map实现很清楚,你可以
: 试试”,自己实在不知道collections和map的高深之处,特别是在我自己的这个程序里
: , 不知可否指点一下? 好虫兄给了一个简明扼要的指点,不知xmlxsd可否指点一下?
: 感激不尽。

avatar
x*d
10
java collections framework is not 高深, I can't agree more, even java is not
, but I see enough people struggling with them.
I always tell beginners to get familiar with collections before doing
anything else. That was my point, but off topic. sometimes it is just hard
to get the message understood.

issues

【在 s******e 的大作中提到】
: Your problem has nothing to do with java colletcions framework. ALso I do
: not think java collections framework is 高深. But that is off the topic.
: Java is a strong type and object oriented language. you should be able to
: find tons of articles and books talking about why an object oriented
: language is better than procedural languages for enterprise applications.
: Using map to save the heterogeneous class states not only defeats the
: purpose of the strong type language, but also fails to mimic the domain
: world and thus reduce the chance of class reuse. Also there are other issues
: , such as casting, inheritance, and coupling.
: I am not saying that you should never do it. In one case, I have used a

avatar
f*0
11
多谢指点。获益匪浅。
顺便请教一个design的问题:
我在写一个球类比赛报名程序,其中需要用户输入几类人的姓名,联系方式,职位,性
别等数据。
问题是由于人的类别不一,输入数据的GUI也相应不一。如何设计这个GUI?
我自己想出来的是,1) 用一个superclass, 多个subclass; 或 2) 用一个class包
含几个constructor,使用时,调用不同的constructor来输入参数。
不知道哪个更好?还是我的选择一开始就错了?

issues

【在 s******e 的大作中提到】
: Your problem has nothing to do with java colletcions framework. ALso I do
: not think java collections framework is 高深. But that is off the topic.
: Java is a strong type and object oriented language. you should be able to
: find tons of articles and books talking about why an object oriented
: language is better than procedural languages for enterprise applications.
: Using map to save the heterogeneous class states not only defeats the
: purpose of the strong type language, but also fails to mimic the domain
: world and thus reduce the chance of class reuse. Also there are other issues
: , such as casting, inheritance, and coupling.
: I am not saying that you should never do it. In one case, I have used a

avatar
g*g
12
This is classic builder pattern.

【在 f*****0 的大作中提到】
: 多谢指点。获益匪浅。
: 顺便请教一个design的问题:
: 我在写一个球类比赛报名程序,其中需要用户输入几类人的姓名,联系方式,职位,性
: 别等数据。
: 问题是由于人的类别不一,输入数据的GUI也相应不一。如何设计这个GUI?
: 我自己想出来的是,1) 用一个superclass, 多个subclass; 或 2) 用一个class包
: 含几个constructor,使用时,调用不同的constructor来输入参数。
: 不知道哪个更好?还是我的选择一开始就错了?
:
: issues

avatar
f*0
13
哈哈! 我在构建data模型的时候,用了builder pattern。
没想到GUI也可以使用。 多谢多谢。

【在 g*****g 的大作中提到】
: This is classic builder pattern.
avatar
s*e
14
I am not sure you should use a gof builder pattern. Based on your
description, it is more like a classic factory method pattern. Or if it is
for ui, a combination of template and composite view patterns.

【在 f*****0 的大作中提到】
: 哈哈! 我在构建data模型的时候,用了builder pattern。
: 没想到GUI也可以使用。 多谢多谢。

avatar
f*0
15
可能我一开始没有把问题说清楚,
关于这个比赛管理程序,纯属个人学习练习。
关于一个比赛的参加人员,分为比赛组织者(分工不同,有不同的头衔),比赛的裁判
(几种),比赛的参加者,而程序的使用者需要输入每个人都有相关的部分或全部的信
息。
这个时候,在构建组织者,裁判,和参加者的时候,我选用了builder模式。
我一开始的问题是,那在构建不同的UI让用户输入不同类人的相关信息的时候,如何构
建这好几个UI (说好几个,是因为有相同的和不同的数据)?我自己一开始拓展使用
了Jdialog。然后再拓展出相应的组织者,裁判,和参加者的对话框。
好虫推荐了builder模式。我觉得这个是个非常好的主意。
我再去学习了一下你说的模板和复合模式,觉得好像不甚适用。请指点。

【在 s******e 的大作中提到】
: I am not sure you should use a gof builder pattern. Based on your
: description, it is more like a classic factory method pattern. Or if it is
: for ui, a combination of template and composite view patterns.

相关阅读
logo
联系我们隐私协议©2024 redian.news
Redian新闻
Redian.news刊载任何文章,不代表同意其说法或描述,仅为提供更多信息,也不构成任何建议。文章信息的合法性及真实性由其作者负责,与Redian.news及其运营公司无关。欢迎投稿,如发现稿件侵权,或作者不愿在本网发表文章,请版权拥有者通知本网处理。