-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adding Interface Segregation and Dependency Inversion principles clas…
…ses examples
- Loading branch information
1 parent
65c099b
commit 0eb7dc2
Showing
9 changed files
with
104 additions
and
0 deletions.
There are no files selected for viewing
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
13 changes: 13 additions & 0 deletions
13
solid/src/main/java/com/jazzinjars/solid/dependency/BackEndDeveloper.java
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package com.jazzinjars.solid.dependency; | ||
|
||
public class BackEndDeveloper implements Developer { | ||
|
||
@Override | ||
public void develop() { | ||
writeJava(); | ||
} | ||
|
||
private void writeJava() { | ||
|
||
} | ||
} |
6 changes: 6 additions & 0 deletions
6
solid/src/main/java/com/jazzinjars/solid/dependency/Developer.java
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
package com.jazzinjars.solid.dependency; | ||
|
||
public interface Developer { | ||
|
||
void develop(); | ||
} |
13 changes: 13 additions & 0 deletions
13
solid/src/main/java/com/jazzinjars/solid/dependency/FrontEndDeveloper.java
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package com.jazzinjars.solid.dependency; | ||
|
||
public class FrontEndDeveloper implements Developer { | ||
|
||
@Override | ||
public void develop() { | ||
writeJavaScript(); | ||
} | ||
|
||
private void writeJavaScript() { | ||
|
||
} | ||
} |
31 changes: 31 additions & 0 deletions
31
solid/src/main/java/com/jazzinjars/solid/dependency/Project.java
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package com.jazzinjars.solid.dependency; | ||
|
||
import java.util.List; | ||
|
||
public class Project { | ||
|
||
private List<Developer> developers; | ||
|
||
// So as we can see the Project class is a high level module and it depends on low level modules | ||
// such as BackEndDeveloper and FrontEndDeveloper. We are actually violating the first part of | ||
// the dependency inversion principle. | ||
// ------> | ||
private BackEndDeveloper backEndDeveloper = new BackEndDeveloper(); | ||
private FrontEndDeveloper frontEndDeveloper = new FrontEndDeveloper(); | ||
|
||
public void implementNoPrinciple() { | ||
// backEndDeveloper.writeJava(); | ||
// frontEndDeveloper.writeJavaScript(); | ||
} | ||
// ------> | ||
|
||
public Project(List<Developer> developers) { | ||
this.developers = developers; | ||
} | ||
|
||
public void implement() { | ||
developers.forEach(d -> d.develop()); | ||
} | ||
} | ||
|
||
|
12 changes: 12 additions & 0 deletions
12
solid/src/main/java/com/jazzinjars/solid/interfacesegregation/Athlete.java
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package com.jazzinjars.solid.interfacesegregation; | ||
|
||
public interface Athlete { | ||
|
||
void compete(); | ||
|
||
// void swim(); | ||
|
||
// void highJump(); | ||
|
||
// void longJump(); | ||
} |
14 changes: 14 additions & 0 deletions
14
solid/src/main/java/com/jazzinjars/solid/interfacesegregation/JohnSmith.java
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package com.jazzinjars.solid.interfacesegregation; | ||
|
||
public class JohnSmith implements SwimmingAthlete { | ||
|
||
@Override | ||
public void compete() { | ||
System.out.println("John Smith started competing"); | ||
} | ||
|
||
@Override | ||
public void swim() { | ||
System.out.println("John Smith started swimming"); | ||
} | ||
} |
8 changes: 8 additions & 0 deletions
8
solid/src/main/java/com/jazzinjars/solid/interfacesegregation/JumpingAthlete.java
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package com.jazzinjars.solid.interfacesegregation; | ||
|
||
public interface JumpingAthlete extends Athlete { | ||
|
||
void highJump(); | ||
|
||
void longJump(); | ||
} |
6 changes: 6 additions & 0 deletions
6
solid/src/main/java/com/jazzinjars/solid/interfacesegregation/SwimmingAthlete.java
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
package com.jazzinjars.solid.interfacesegregation; | ||
|
||
public interface SwimmingAthlete extends Athlete { | ||
|
||
void swim(); | ||
} |