Created
April 12, 2016 20:17
-
-
Save malalanayake/a3f898c88f8d55a18cfac53e915bb5cc to your computer and use it in GitHub Desktop.
Dependency Inversion principal - Bad sample code
This file contains hidden or 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
package sample.dependency.Inversion.bad; | |
/** | |
* | |
* Distibution under GNU GENERAL PUBLIC LICENSE Version 2, June 1991 | |
* | |
* @author dmalalan | |
* @created Apr 12, 2016 2:48:43 PM | |
* | |
* @blog https://malalanayake.wordpress.com/ | |
*/ | |
public class ApplicationProgram { | |
public void run() { | |
System.out.println("[RUN:Application]"); | |
} | |
} |
This file contains hidden or 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
package sample.dependency.Inversion.bad; | |
/** | |
* | |
* Distibution under GNU GENERAL PUBLIC LICENSE Version 2, June 1991 | |
* | |
* @author dmalalan | |
* @created Apr 12, 2016 2:58:58 PM | |
* | |
* @blog https://malalanayake.wordpress.com/ | |
*/ | |
public class Main { | |
public static void main(String[] args) { | |
ApplicationProgram app = new ApplicationProgram(); | |
ServiceProgram service = new ServiceProgram(); | |
OperatingSystem os = new OperatingSystem(); | |
os.start(app); | |
os.start(service); | |
} | |
} |
This file contains hidden or 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
package sample.dependency.Inversion.bad; | |
/** | |
* | |
* Distibution under GNU GENERAL PUBLIC LICENSE Version 2, June 1991 | |
* | |
* @author dmalalan | |
* @created Apr 12, 2016 2:48:03 PM | |
* | |
* @blog https://malalanayake.wordpress.com/ | |
*/ | |
public class OperatingSystem { | |
private ApplicationProgram app; | |
private ServiceProgram service; | |
public void start(ApplicationProgram app) { | |
this.app = app; | |
app.run(); | |
} | |
public void start(ServiceProgram service) { | |
this.service = service; | |
service.run(); | |
} | |
} |
This file contains hidden or 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
package sample.dependency.Inversion.bad; | |
/** | |
* | |
* Distibution under GNU GENERAL PUBLIC LICENSE Version 2, June 1991 | |
* | |
* @author dmalalan | |
* @created Apr 12, 2016 2:49:09 PM | |
* | |
* @blog https://malalanayake.wordpress.com/ | |
*/ | |
public class ServiceProgram { | |
public void run() { | |
System.out.println("[RUN:Service]"); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment