コード例 #1
0
        public static void Run()
        {
            PropertyManagerHelper propertyManagerHelper = new PropertyManagerHelper();

            IPropertyManager[] propertyManagers =
                propertyManagerHelper.GetPropertyManagers();

            HomeRentalSearchParams homeRentalSearchParams = new HomeRentalSearchParams();

            homeRentalSearchParams.ZipCode            = "94093";
            homeRentalSearchParams.RentRangeValueFrom = 2000;
            homeRentalSearchParams.RentRangeValueTo   = 4000;
            homeRentalSearchParams.NumberOfBedrooms   = 2;
            homeRentalSearchParams.PropertyType       = PropertyType.Condo;

            List <RentalHome> rentalHomes = new List <RentalHome>();

            foreach (IPropertyManager propertyManager in propertyManagers)
            {
                // Here, the method SearchForRentals is coming from different concrete classes but they all implement the same interface.
                // Hence, we have achieved the polymorphism in interfaces since they call the same methods from their respective classes.
                rentalHomes.AddRange(propertyManager.SearchForRentals(homeRentalSearchParams));
            }

            rentalHomes.ForEach(item => Console.WriteLine(item));
        }
コード例 #2
0
 public RentalHome[] SearchForRentals(HomeRentalSearchParams homeRentalSearchParams)
 {
     return(new RentalHome[] { new RentalHome("AirBNB Rental Home Listing - 1"), new RentalHome("AirBNB Rental Home Listing - 2"), new RentalHome("AirBNB Rental Home Listing - 3"), });
 }