我目前正在开发一个简单的Java游戏,有几种不同的模式.我扩展了一个主要的Game类,将主要逻辑放在其他类中.尽管如此,主要的游戏类仍然非常沉重.
在快速浏览一下我的代码后,其中大部分是Getters and Setters(60%),而其余部分则是游戏逻辑真正需要的.
一些谷歌搜索声称Getters和Setters是邪恶的,而其他人声称他们是良好的OO练习和伟大的程序所必需的.
所以我该怎么做?应该是哪个?我应该为我的私人变量更改我的Getters和Setter,还是应该坚持使用它们?
使用jaxb,我尝试读取xml文件只有xml文件中的一些元素很有趣,所以我想跳过很多元素
xml我尝试阅读
<?xml version="1.0" encoding="UTF-8"?>
<!--Sample XML file generated by XMLSpy v2010 rel. 3 sp1 (http://www.altova.com)-->
<flx:ModeleREP xsi:schemaLocation="urn:test:mod_rep.xsd mod_rep.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:flx="urn:test:mod_rep.xsd">
<flx:DocumentHeader>
<flx:Identification v="04489"/>
</flx:DocumentHeader>
<flx:TimeSeries>
<flx:Identification v="test1a"/>
<flx:BusinessType v="A01"/>
<flx:Product v="123a"/>
<flx:ResourceObject codingScheme="N" v="testa"/>
<flx:Period>
<flx:TimeInterval v="2011-07-02T00:00/2011-07-16T00:00"/>
<flx:Resolution v="PT2H"/>
<flx:Pt>
<flx:P v="1"/>
<flx:Q unitCode="String" v="1.0"/>
<flx:A currencyIdentifier="String" v="195.0"/>
</flx:Pt>
</flx:Period>
</flx:TimeSeries>
<flx:TimeSeries>
<flx:Identification v="test2a"/>
<flx:BusinessType v="A01"/>
<flx:Product v="a123b"/>
<flx:ResourceObject codingScheme="N" v="test2"/>
<flx:Period>
<flx:TimeInterval v="2011-07-02T00:00/2011-07-16T00:00"/>
<flx:Resolution v="PT2H"/>
<flx:Pt>
<flx:P v="1"/>
<flx:Q unitCode="String" v="1.0"/>
<flx:A currencyIdentifier="String" v="195.0"/>
</flx:Pt>
<flx:Pt>
<flx:P …Run Code Online (Sandbox Code Playgroud) java n00b在这里.
我有一个自定义数据类型定义如下:
public class MyData{
int value;
int type;
String name;
public MyData(int newValue, int newType, string newName)
{
value = newValue;
type = newType;
name = newName;
}
}
Run Code Online (Sandbox Code Playgroud)
当我调用这个类的实例时,我希望它计算value属性,如下所示:
myData dataInstance = new myData(100,3,"customData");
System.out.println(dataInstance); // should print "100"
Run Code Online (Sandbox Code Playgroud)
这可以实现吗?