0
0
C Sharp (C#)programming~20 mins

Multiple interface implementation in C Sharp (C#) - Mini Project: Build & Apply

Choose your learning style9 modes available
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
1
Create interfaces IPrinter and IScanner
Create an interface called IPrinter with a method Print() that returns void. Also create an interface called IScanner with a method Scan() that returns void.
C Sharp (C#)
Need a hint?

Use the interface keyword to create interfaces. Define methods without bodies.

2
Create class MultiFunctionDevice implementing both interfaces
Create a class called MultiFunctionDevice that implements both IPrinter and IScanner. Do not add method bodies yet.
C Sharp (C#)
Need a hint?

Use class ClassName : Interface1, Interface2 syntax to implement multiple interfaces.

3
Implement Print() and Scan() methods
In the MultiFunctionDevice class, implement the Print() method to print "Printing document..." and the Scan() method to print "Scanning document..." using Console.WriteLine.
C Sharp (C#)
Need a hint?

Use Console.WriteLine("message") inside each method to print the messages.

4
Create object and call methods to display output
Create an object called device of type MultiFunctionDevice. Call the Print() method on device. Then call the Scan() method on device. This will print the messages to the console.
C Sharp (C#)
Need a hint?

Create the object and call the methods inside a Main method to see the output.