Skip to content

Instantly share code, notes, and snippets.

@krohit-bkk
Created January 21, 2024 14:34
Show Gist options
  • Save krohit-bkk/f01ec21a607a3653b02092dce7ad3dda to your computer and use it in GitHub Desktop.
Save krohit-bkk/f01ec21a607a3653b02092dce7ad3dda to your computer and use it in GitHub Desktop.
Code snippet 2 for Interface Segregation Principle
// 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();
}
}
@krohit-bkk
Copy link
Author

Uploading Blogging_Scratch_notes.drawio (10).png…

@krohit-bkk
Copy link
Author

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