Analyzing the Delegation Code
The Main() method begins by creating an instance of the Garage and ServiceDepartment types. Now,
when you write the following:
// Wash all dirty cars.
g.ProcessCars(new Car.CarMaintenanceDelegate(sd.WashCar));
what you are effectively saying is, “Insert the address of the ServiceDepartment.WashCar() method
to a Car.CarMaintenanceDelegate object, and pass this object to Garage.ProcessCars().” Like most
real-world garages, the real work is delegated to the service department (which explains why a
30-minute oil change takes 2 hours). Given this, ProcessCars() can be understood as
Do'stlaringiz bilan baham: |