Created
January 21, 2024 10:21
-
-
Save krohit-bkk/4a4f6660f1f2ea88e274e617a64e594f to your computer and use it in GitHub Desktop.
Code snippet 1 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
// Interface Tasks | |
interface Tasks { | |
void code(); | |
void test(); | |
} | |
// Class Assignee | |
abstract class Assignee implements Tasks {} | |
// Developer is an Assingee | |
class Developer extends Assignee { | |
@Override | |
public void code() { System.out.println("I can code!"); } | |
@Override | |
public void test() { | |
System.out.println("throw new UnsupportedOperationException('I can\'t test!')"); } | |
} | |
// Tester is an Assingee | |
class Tester extends Assignee { | |
@Override | |
public void code() { | |
System.out.println("throw new UnsupportedOperationException('I can\'t code!');"); } | |
@Override | |
public void test() { System.out.println("I can test!"); } | |
} | |
public class ISP1 { | |
public static void main(String[] args) { | |
Assignee coder = new Developer(); | |
Assignee tester = new Tester(); | |
coder.code(); | |
coder.test(); | |
System.out.println(); | |
tester.test(); | |
tester.code(); | |
} | |
} |
Author
krohit-bkk
commented
Jan 21, 2024
Program output:
I can code!
throw new UnsupportedOperationException('I can't test!')
I can test!
throw new UnsupportedOperationException('I can't code!');
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment