ISP in Device System
This program applies ISP to device system.
Problem Statement
Write a Java program where Printer and Scanner interfaces are separated.
Source Code
| 1 | interface Printer { void print(); } |
| 2 | interface Scanner { void scan(); } |
| 3 | class SimplePrinter implements Printer { |
| 4 | public void print(){ System.out.println("Printing document"); } |
| 5 | } |
| 6 | public class ISPDevice { |
| 7 | public static void main(String[] args) { |
| 8 | System.out.println("Eduinq ISP Device"); |
| 9 | Printer p=new SimplePrinter(); |
| 10 | p.print(); |
| 11 | } |
| 12 | } |
Program Output
Eduinq ISP Device Printing document
Explanation
ISP avoids forcing classes to implement unused methods. - SimplePrinter only implements Printer. - This improves cohesion and reduces unnecessary complexity. Conclusion: Shows ISP applied to device system.