public void Print() { // Lớp ConcreteDependency sử dụng trực tiếp lớp HP Printer HPPrinter worker = new HPPrinter(); worker.Print(); }
static void Main(string[] args) { Console.WriteLine("This is concrete Dependency"); ConcreteDependency concreteDependency = new ConcreteDependency(); concreteDependency.Print(); Console.WriteLine("This is abstract Dependency"); AbstractDependency abstractDependency = new AbstractDependency(); IPrinter hpPrinter = new HPPrinter(); IPrinter canonPrinter = new CanonPrinter(); abstractDependency.Print(hpPrinter); abstractDependency.Print(canonPrinter); Console.ReadLine(); }