[英]How to use an object that got return in another class
I have this class, that returns an object, if the email, password and category (enum) are correct:我有这个类,它返回一个对象,如果电子邮件、密码和类别(枚举)是正确的:
public class LoginManager {
private static LoginManager instance = new LoginManager();
private LoginManager() {
super();
}
public static LoginManager getInstance() {
return instance;
}
public ClientFacade login(String email, String password, ClientType clientType) throws SQLException {
if (clientType == ClientType.Administrator) {
AdminFacade adminFacade = new AdminFacade();
if (adminFacade.login(email, password) == true) {
return adminFacade;
} else {
return null;
}
} else if (clientType == ClientType.Company) {
CompanyFacade companyFacade = new CompanyFacade();
if (companyFacade.login(email, password) == true) {
return companyFacade;
} else {
return null;
}
} else if (clientType == ClientType.Customer) {
CustomerFacade customerFacade = new CustomerFacade();
if (customerFacade.login(email, password) == true) {
return customerFacade;
} else {
return null;
}
} else {
return null;
}
}
}
How do I use that object in another class?我如何在另一个类中使用该对象? This is the other class, that is supposed to use the object that return:
这是另一个类,应该使用返回的对象:
public class Test {
CouponsDBDAO coupDBD = new CouponsDBDAO();
CouponExpirationDailyJob dailyJob =
new CouponExpirationDailyJob(coupDBD, false);
LoginManager Log = LoginManager.getInstance();
public void testAll() {
try {
Log.login("admin@admin.com", "admin", ClientType.Administrator); {
}
} catch (SQLException e) {
System.out.println(e.getMessage());
}
}
}
How do I use now the adminFacade for example?例如,我现在如何使用 adminFacade?
try尝试
LoginManager Log = new LoginManager();
public void testAll() {
try {
ClientFacade facade = Log.login("admin@admin.com", "admin", ClientType.Administrator);
facade.DoSomethingUseful();
} catch (SQLException e) {
System.out.println(e.getMessage());
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.