コード例 #1
0
ファイル: CSharpOOP.cs プロジェクト: kingojem/Learn-CSharp
        static void InitializePilots()
        {
            #region Create Pilots Object or Instances
            Pilots pilot1 = new Pilots()
            {
                Name           = "Emmanuel",
                ID             = 564,
                Experience     = 11,
                Marital_Status = false
            };
            Pilots pilot2 = new Pilots();
            pilot2.Experience     = 6;
            pilot2.Name           = "Peter";
            pilot2.Marital_Status = true;
            Pilots pilot3 = new Pilots(23, "Jamiu", 13, null);
            #endregion

            #region Assemble TOtal List Of Pilots
            // Create A LIst Of Pilots

            List <Pilots> P = new List <Pilots>();
            P.Add(pilot1);
            P.Add(pilot2);
            P.Add(pilot3);
            // Pilots.Promoteworker(P); // This Has an Hard Coded Logic and its not flexible, especially if this a framework that assist other developers promote thier workers

            // Initializing My Delegate
            #endregion

            #region Delegate Call, Logic And Function Call (In a Real life Framework, I can ensure this or this would be done by the tird party calling my code)
            Pilots.IsPromotable isPromotable = new Pilots.IsPromotable(PromoteWorker);

            //This is Now The User Utilized Function That Ensures the Kind Of lOgic That is Needed for Thier bussiness

            bool PromoteWorker(Pilots pilots)
            {
                //The Logic

                if (pilots.Experience >= 10)
                {
                    return(true);
                }
                else
                {
                    return(false);
                }
            }

            Pilots.PromotePilots(P, isPromotable);

            #endregion

            //Function Call
        }