简体   繁体   English

如何使用在另一个类中返回的对象

[英]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.

相关问题 如何使用自定义 object 将 int 和 double 连接到字符串并返回另一个 class 中的值 - How to use a custom object to concate a int and double to a string and return the value in another class Java:如何使用另一个类中的对象 - Java: how to use an object from another class 在另一个 class 中使用 object - Use an object in another class 如何在Android的另一个类中使用方法的返回值 - How to use return value of a method in a another class in android 如何使用Java使用另一个类的返回字符串? - How to use a return string of another class using Java? 如何存储返回列表,以便可以在另一个类中使用它? - How to store the return list so I can use it in another class? 如何使用另一个Java类的方法返回 - How to use method return from another Java class 如何获取另一个文件中一个类中已经存在的对象的数据,并将其用于Java中另一个文件中的另一个类? - How to get data of an object that already existed in one class in another file and use it to another class in another file in Java? 如何使用另一个类中的对象的特定变量? - How do I use a specific variable of an object that is in another class? 如何将对象中的 Arraylist 用于另一个类中的方法 - How can I use an Arraylist in an object for a method in another class
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM