static void Main(string[] args) { var myEmployees = new List <Employee>(); //Create a list of the base class that we want to perform aggregate operations on Employee myWorker = new Worker("Jim Halpert"); //Create Jim myEmployees.Add(new HighPerformer(myWorker)); //Add Jim to the list, but as a high performer Employee myManager = new Manager("Michael Scott"); //Create Michael Scott myManager = new SoftballPlayer(myManager); //Michae plays softball.... myEmployees.Add(new SafetyTeamMember(myManager)); //... and he's on the safety team, so add him with both of these decorators myEmployees.Add(new Executive("Jan Levenson")); //Jan doesn't do anything until we add a decorator for inappropriate subordinate relationships, so add her as-is PrintAllEmployees(myEmployees); //And, print all of them, observing that the decorators do their work without clients needing to have conditional logic or other awkwardness }
static void Main(string[] args) { var myEmployees = new List<Employee>(); //Create a list of the base class that we want to perform aggregate operations on Employee myWorker = new Worker("Jim Halpert"); //Create Jim myEmployees.Add(new HighPerformer(myWorker)); //Add Jim to the list, but as a high performer Employee myManager = new Manager("Michael Scott"); //Create Michael Scott myManager = new SoftballPlayer(myManager); //Michae plays softball.... myEmployees.Add(new SafetyTeamMember(myManager)); //... and he's on the safety team, so add him with both of these decorators myEmployees.Add(new Executive("Jan Levenson")); //Jan doesn't do anything until we add a decorator for inappropriate subordinate relationships, so add her as-is PrintAllEmployees(myEmployees); //And, print all of them, observing that the decorators do their work without clients needing to have conditional logic or other awkwardness }