1 回答
TA贡献1820条经验 获得超10个赞
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
添加回答
举报