コード例 #1
0
ファイル: Program.cs プロジェクト: thehound0/sharedrepo
        static void Main(string[] args)
        {
            #region factory method pattern
            //contract employee
            var employee = new FactoryMethod.Employee
            {
                //EmployeeTypeID = 1,
                EmployeeTypeID   = 2,
                Bonus            = 100,
                HourlyPay        = 40,
                HouseAllowance   = 40,
                MedicalAllowance = 30
            };
            BaseEmployeeFactory empFactory =
                new EmployeeManagerFactory().CreateFactory(employee);
            empFactory.ApplySalary();
            Console.WriteLine($"Employee: {employee.EmployeeTypeID}{Environment.NewLine} " +
                              $"House Allowance: {employee.HouseAllowance}{Environment.NewLine} " +
                              $"Medical Allowance: {employee.MedicalAllowance}");
            #endregion

            #region Abstract Factory Method
            var abstractFactoryEmployee   = new Employee {
            };
            IComputerFactory      factory = new EmployeeSystemFactory().Create(abstractFactoryEmployee);
            EmployeeSystemManager manager = new EmployeeSystemManager(factory);
            abstractFactoryEmployee.ComputerDetails = manager.GetSystemDetails();
            Console.WriteLine($"Computer Details: {abstractFactoryEmployee.ComputerDetails}{Environment.NewLine} " +
                              $"Job Description: {abstractFactoryEmployee.JobDescription}");
            #endregion

            #region Singleton Pattern

            /*
             * Assuming Singleton is created from employee class
             * we refer to the GetInstance property from the Singleton class
             */
            DesignPatterns.Singleton.Singleton fromEmployee = DesignPatterns.Singleton.Singleton.GetInstance;
            fromEmployee.PrintDetails("From Employee");

            /*
             * Assuming Singleton is created from student class
             * we refer to the GetInstance property from the Singleton class
             */
            DesignPatterns.Singleton.Singleton fromStudent = DesignPatterns.Singleton.Singleton.GetInstance;
            fromStudent.PrintDetails("From Student");
            #endregion

            #region Decorator Pattern
            ICar         car       = new Suzuki();
            CarDecorator decorator = new OfferPrice(car);
            Console.WriteLine(string.Format("Make :{0}  Price:{1} " +
                                            "DiscountPrice : {2}"
                                            , decorator.Make, decorator.GetPrice().ToString(),
                                            decorator.GetDiscountedPrice().ToString()));
            #endregion

            Console.ReadLine();
        }
コード例 #2
0
        static void Main(string[] args)
        {
            ICar         car       = new Suzuki();
            CarDecorator decorator = new OfferPrice(car);

            Console.WriteLine($"Make: {car.Make} Price: {car.GetPrice().ToString()} " +
                              $"DiscountedPrice: {decorator.GetDiscountedPrice().ToString()}");
        }
コード例 #3
0
ファイル: Program.cs プロジェクト: Suraj21/.NetDesignPatterns
        static void Main(string[] args)
        {
            ICar         car       = new Suzuki();
            CarDecorator decorator = new OfferPrice(car);

            Console.WriteLine(String.Format("Make :{0} Price: {1}" + "Discounted Price: {2}", decorator.Make, decorator.GetPrice().ToString(),
                                            decorator.GetDiscountedPrice().ToString()));

            Console.ReadLine();
        }
コード例 #4
0
        static void Main(string[] args)
        {
            var car       = new Suzuki();
            var decorator = new OfferPrice(car);

            Console.WriteLine($"Make {decorator.Make} Price {decorator.GetPrice()} + DiscountedPrice {decorator.GetDiscountedPrice()}");

            Console.ReadLine();
        }