Skip to content

Instantly share code, notes, and snippets.

@malalanayake
Created April 12, 2016 20:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save malalanayake/a3f898c88f8d55a18cfac53e915bb5cc to your computer and use it in GitHub Desktop.
Save malalanayake/a3f898c88f8d55a18cfac53e915bb5cc to your computer and use it in GitHub Desktop.
Dependency Inversion principal - Bad sample code
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]");
}
}
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);
}
}
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();
}
}
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