1 回答

TA貢獻(xiàn)1820條經(jīng)驗(yàn) 獲得超10個(gè)贊
Configuration將類與類分開EmailReceiver:
// Utilizes "Singleton" pattern
class GmailConfiguration {
private static final GmailConfiguration INSTANCE = new GmailConfiguration();
boolean isConfigured;
String host;
String port;
//etc.
public void configure() {
if (!isConfigured) {
// read in the properties, populate host/port etc.
isConfigured = true;
}
// when called for the second time, reading won't happen
}
}
然后,至于接收電子郵件:
class GmailReceiver {
public void receive() {
AccessMailMessages readGmail = new AccessMailMessages();
GmailConfiguration config = GmailConfiguration.INSTANCE;
config.configure();
readGmail.recieveGmail(config.getName(),
config.getHost(),
config.getPort() /* etc */);
}
}
并確保只安排GmailReceiver
添加回答
舉報(bào)