Beispiel #1
0
        static void Main(string[] args)
        {
            ProxyFactory factory = new ProxyFactory();

            AdminProxy    admin    = (AdminProxy)factory.Login("Admin", "Admin");
            CustomerProxy customer = (CustomerProxy)factory.Login("Customer", "Customer");
            CompanyProxy  company  = (CompanyProxy)factory.Login("Company", "Company");

            admin.CreateCompany("ELAL");
            admin.CreateCustomer("Moshe");
            customer.BuyTicket("To Italia");
            customer.ShowMyTickets();
            company.CancelFlight("To Maldives");
            company.CreateFlight("To Spain");
        }
        public ClientProxy Login(string username, string pw)
        {
            if (username == "Admin" && pw == "Admin")
            {
                ClientProxy adminProxy = new AdminProxy();
                return(adminProxy);
            }
            if (username == "Company" && pw == "Company")
            {
                ClientProxy CompanyProxy = new CompanyProxy();
                return(CompanyProxy);
            }
            if (username == "Customer" && pw == "Customer")
            {
                ClientProxy CustomerProxy = new CustomerProxy();
                return(CustomerProxy);
            }

            throw new Exception("Credentials are not valid!");
        }