Created
January 21, 2024 14:34
-
-
Save krohit-bkk/f01ec21a607a3653b02092dce7ad3dda to your computer and use it in GitHub Desktop.
Code snippet 2 for Interface Segregation Principle
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// class Assignee | |
abstract class Assignee {} | |
// Interface Dev for Developer tasks | |
interface Dev { void code(); } | |
// Interface QA for Test tasks | |
interface QA { void test(); } | |
// Developer is an Assingee | |
class Developer extends Assignee implements Dev { | |
@Override | |
public void code() { System.out.println("Developer can code!"); } | |
} | |
// Tester is an Assingee | |
class Tester extends Assignee implements QA { | |
@Override | |
public void test() { System.out.println("Tester can test!"); } | |
} | |
// ProjectLead is an Assignee | |
class ProjectLead extends Assignee implements Dev, QA { | |
@Override | |
public void code() { System.out.println("ProjectLead can code!"); } | |
@Override | |
public void test() { System.out.println("ProjectLead can test!"); } | |
} | |
public class ISP2 { | |
public static void main(String[] args) { | |
Developer coder = new Developer(); | |
Tester tester = new Tester(); | |
ProjectLead lead = new ProjectLead(); | |
coder.code(); | |
tester.test(); | |
lead.code(); | |
lead.test(); | |
} | |
} |
Author
krohit-bkk
commented
Jan 21, 2024
Program output:
Developer can code!
Tester can test!
ProjectLead can code!
ProjectLead can test!
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment