Multiple interface implementation
📖 Scenario: Imagine you are building a simple system where a device can perform multiple roles. For example, a device can act as a printer and a scanner. Each role has its own set of actions defined by interfaces.
🎯 Goal: You will create two interfaces IPrinter and IScanner, then create a class MultiFunctionDevice that implements both interfaces. Finally, you will create an object of this class and call both printing and scanning methods.
📋 What You'll Learn
Create an interface called
IPrinter with a method Print() that returns void.Create an interface called
IScanner with a method Scan() that returns void.Create a class called
MultiFunctionDevice that implements both IPrinter and IScanner.Implement the
Print() method in MultiFunctionDevice to print the message "Printing document...".Implement the
Scan() method in MultiFunctionDevice to print the message "Scanning document...".Create an object of
MultiFunctionDevice and call both Print() and Scan() methods.Print the output messages exactly as specified.
💡 Why This Matters
🌍 Real World
Many devices like printers, scanners, and fax machines have multiple functions. Using multiple interfaces models this real-world scenario in code.
💼 Career
Understanding multiple interface implementation is important for designing clean, maintainable, and flexible software in professional C# development.
Progress0 / 4 steps