//存放參會者身上戴的牌子所顯示的信息.
public class Badge {
String pid; //參會者 ID
String engName; //英文全名
String chiName; //中文全名
String engOrgName; //所在部門英文名稱
String chiOrgName; //所在部門中文名稱
String engCountry; //部門所在國家的中文名稱
String chiCountry; //部門所在國家的英文名稱
//***********************
//構造函數.
//根據參會者的id,去數據庫取出該參與者的信息.
//***********************
Badge(String pid) {
this.pid = pid;
//***********************
//取出參會者
//***********************
ParticipantsInDB partsInDB = ParticipantsInDB.getInstance();
Participant part = partsInDB.locateParticipant(pid);
if (part != null) {
//取出參會者的英文全名
engName = part.getELastName() + ", " + part.getEFirstName();
//取出參會者的中文全名
chiName = part.getCLastName()+part.getCFirstName();
//***********************
//取出所在部門跟國家.
//***********************
OrganizationsInDB orgsInDB = OrganizationsInDB.getInstance();
//取出所在部門的id.
String oid = orgsInDB.getOrganization(pid);
if (oid != null) {
Organization org = orgsInDB.locateOrganization(oid);
engOrgName = org.getEName();
chiOrgName = org.getCName();
engCountry = org.getEAddress().getCountry();
chiCountry = org.getCAddress().getCountry();
}
}
}
...
}
//存放參會者身上戴的牌子所顯示的信息.
public class Badge {
...
}
public class ParticipantInfoOnBadge {
...
}
Consider:
public class ParticipantInfoOnBadge {
String pid; //參會者 ID
String engName; //英文全名
String chiName; //中文全名
String engOrgName; //所在部門英文名稱
String chiOrgName; //所在部門中文名稱
String engCountry; //部門所在國家的中文名稱
String chiCountry; //部門所在國家的英文名稱
...
}
public class ParticipantInfoOnBadge {
String participantId;
String participantEngFullName;
String participantChiFullName;
String engOrgName;
String chiOrgName;
String engOrgCountry;
String chiOrgCountry;
...
}
public class ParticipantInfoOnBadge {
...
//***********************
//構造函數.
//根據參會者的id,從數據庫取出該參與者的信息.
//***********************
ParticipantInfoOnBadge(String pid) {
this.pid = pid;
...
}
}
public class ParticipantInfoOnBadge {
...
//***********************
//構造函數.
//從數據庫取出該參與者的信息.
//***********************
ParticipantInfoOnBadge(String participantId) {
this.participantId = participantId;
...
}
}
public class ParticipantInfoOnBadge {
...
//***********************
//構造函數.
//***********************
ParticipantInfoOnBadge(String participantId) {
loadInfoFromDB(participantId);//現在,看一下這個構造函數內部,我們就能知道這個構造函數是做什么了吧.
}
void loadInfoFromDB(String participantId) {
this.participantId = participantId;
...
}
}
public class ParticipantInfoOnBadge {
...
//***********************
//構造函數.
//***********************
ParticipantInfoOnBadge(String participantId) {
...
}
}
public class ParticipantInfoOnBadge {
...
ParticipantInfoOnBadge(String participantId) {
...
}
}
void loadInfoFromDB(String participantId) {
this.participantId = participantId;
//***********************
//取得參會者的全名.
//***********************
ParticipantsInDB partsInDB = ParticipantsInDB.getInstance();
Participant part = partsInDB.locateParticipant(participantId);
if (part != null) {
//取得參會者的英文全名.
engFullName = part.getELastName() + ", " + part.getEFirstName();
//取得參會者的中文全名.
chiFullName = part.getCLastName()+part.getCFirstName();
//***********************
//取得參會者所在部門和國家.
//***********************
OrganizationsInDB orgsInDB = OrganizationsInDB.getInstance();
//取得參會者被雇傭部門的id.
String oid = orgsInDB.getOrganization(participantId);
if (oid != null) {
Organization org = orgsInDB.locateOrganization(oid);
engOrgName = org.getEName();
chiOrgName = org.getCName();
engOrgCountry = org.getEAddress().getCountry();
chiOrgCountry = org.getCAddress().getCountry();
}
}
}
void loadInfoFromDB(String participantId) {
this.participantId = participantId;
getParticipantFullNames(); //(取得參會者的全名,注意,我們已經將注釋去掉了.)
//***********************
//取得參會者所在部門和國家.
//***********************
//取得參會者被雇傭部門的id.
OrganizationsInDB orgsInDB = OrganizationsInDB.getInstance();
String oid = orgsInDB.getOrganization(participantId);
if (oid != null) {
Organization org = orgsInDB.locateOrganization(oid);
engOrgName = org.getEName();
chiOrgName = org.getCName();
engOrgCountry = org.getEAddress().getCountry();
chiOrgCountry = org.getCAddress().getCountry();
}
}
void getParticipantFullNames() {
ParticipantsInDB partsInDB = ParticipantsInDB.getInstance();
Participant part = partsInDB.locateParticipant(participantId);
if (part != null) {
//取得參會者的英文全名.
engFullName = part.getELastName() + ", " + part.getEFirstName();
//取得參會者的中文全名.
chiFullName = part.getCLastName()+part.getCFirstName();
}
}
void loadInfoFromDB(String participantId) {
this.participantId = participantId;
getParticipantFullNames();
getOrgNameAndCountry(); //又抽取掉了一個注釋
}
void getParticipantFullNames() {
ParticipantsInDB partsInDB = ParticipantsInDB.getInstance();
Participant part = partsInDB.locateParticipant(participantId);
if (part != null) {
//取得參會者的英文全名.
engFullName = part.getELastName() + ", " + part.getEFirstName();
//取得參會者的中文全名.
chiFullName = part.getCLastName()+part.getCFirstName();
}
}
void getOrgNameAndCountry() {
OrganizationsInDB orgsInDB = OrganizationsInDB.getInstance();
//取得參會者被雇傭部門的id.
String oid = orgsInDB.getOrganization(participantId);
if (oid != null) {
Organization org = orgsInDB.locateOrganization(oid);
engOrgName = org.getEName();
chiOrgName = org.getCName();
engOrgCountry = org.getEAddress().getCountry();
chiOrgCountry = org.getCAddress().getCountry();
}
}
public class ParticipantInfoOnBadge {
...
void getParticipantFullNames() {
ParticipantsInDB partsInDB = ParticipantsInDB.getInstance();
Participant part = partsInDB.locateParticipant(participantId);
if (part != null) {
//取得參會者的英文全名.
engFullName = part.getELastName() + ", " + part.getEFirstName();
//取得參會者的中文全名.
chiFullName = part.getCLastName()+part.getCFirstName();
}
}
}
public class ParticipantInfoOnBadge {
...
void getParticipantFullNames() {
ParticipantsInDB partsInDB = ParticipantsInDB.getInstance();
Participant part = partsInDB.locateParticipant(participantId);
if (part != null) {
engFullName = part.getEFullName(); //將職責交給domain自己,也就是Participant.
chiFullName = part.getCFullName();
}
}
}
public class Participant {
String getEFullName() {
return getELastName() + ", " + getEFirstName();
}
String getCFullName() {
return getCLastName() + getCFirstName();
}
}
public class ParticipantInfoOnBadge {
...
void getOrgNameAndCountry() {
OrganizationsInDB orgsInDB = OrganizationsInDB.getInstance();
//取得參會者被雇傭部門的id.
String oid = orgsInDB.getOrganization(participantId);
if (oid != null) {
Organization org = orgsInDB.locateOrganization(oid);
engOrgName = org.getEName();
chiOrgName = org.getCName();
engOrgCountry = org.getEAddress().getCountry();
chiOrgCountry = org.getCAddress().getCountry();
}
}
}
public class ParticipantInfoOnBadge {
...
void getOrgNameAndCountry() {
OrganizationsInDB orgsInDB = OrganizationsInDB.getInstance();
String oid = orgsInDB.findOrganizationEmploying(participantId);
if (oid != null) {
Organization org = orgsInDB.locateOrganization(oid);
engOrgName = org.getEName();
chiOrgName = org.getCName();
engOrgCountry = org.getEAddress().getCountry();
chiOrgCountry = org.getCAddress().getCountry();
}
}
}
public class OrganizationsInDB {
...
void findOrganizationEmploying(String participantId) {
...
}
}
原文轉自:http://www.anti-gravitydesign.com