using System;
public class Test
{
public static void Main()
{
IComputer computer = new KeyBoard(new Monitor(new Disk(new Computer())));
Console.WriteLine(" You are getting a " + computer.getComputer());
}
}
public interface IComputer
{
string getComputer();
}
public sealed class Computer : IComputer
{
public string getComputer()
{
return "computer";
}
}
public class Disk : IComputer
{
IComputer computer;
public Disk(IComputer c)
{
computer = c;
}
public String getComputer()
{
return computer.getComputer() + " and a disk";
}
}
public class Monitor : IComputer
{
IComputer computer;
public Monitor(IComputer c)
{
computer = c;
}
public String getComputer()
{
return computer.getComputer() + " and a Monitor";
}
}
public class KeyBoard : IComputer
{
IComputer computer;
public KeyBoard(IComputer c)
{
computer = c;
}
public String getComputer()
{
return computer.getComputer() + " and a KeyBoard";
}
}
dXNpbmcgU3lzdGVtOwoKcHVibGljIGNsYXNzIFRlc3QKewoJcHVibGljIHN0YXRpYyB2b2lkIE1haW4oKQoJewoJCUlDb21wdXRlciBjb21wdXRlciA9IG5ldyBLZXlCb2FyZChuZXcgTW9uaXRvcihuZXcgRGlzayhuZXcgQ29tcHV0ZXIoKSkpKTsKCgkJQ29uc29sZS5Xcml0ZUxpbmUoIiBZb3UgYXJlIGdldHRpbmcgYSAiICsgY29tcHV0ZXIuZ2V0Q29tcHV0ZXIoKSk7Cgl9Cn0KCnB1YmxpYyBpbnRlcmZhY2UgSUNvbXB1dGVyCnsKCXN0cmluZyBnZXRDb21wdXRlcigpOwp9CgpwdWJsaWMgc2VhbGVkIGNsYXNzIENvbXB1dGVyIDogSUNvbXB1dGVyCnsKCXB1YmxpYyBzdHJpbmcgZ2V0Q29tcHV0ZXIoKQoJewoJCXJldHVybiAiY29tcHV0ZXIiOwoJfQp9CgpwdWJsaWMgY2xhc3MgRGlzayA6IElDb21wdXRlcgp7CglJQ29tcHV0ZXIgY29tcHV0ZXI7CglwdWJsaWMgRGlzayhJQ29tcHV0ZXIgYykKCXsKCQljb21wdXRlciA9IGM7Cgl9CgoJcHVibGljIFN0cmluZyBnZXRDb21wdXRlcigpCgl7Cgk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