Created
April 12, 2016 20:20
-
-
Save malalanayake/e2647e2c086839f1f7a348e592cbf55c to your computer and use it in GitHub Desktop.
Dependency Inversion principal - Good sample code
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
package sample.dependency.Inversion.good; | |
/** | |
* | |
* 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 ApplicationProgramNew implements Runner { | |
public void run() { | |
System.out.println("[RUN:Application]"); | |
} | |
} |
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
package sample.dependency.Inversion.good; | |
/** | |
* | |
* 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) { | |
ApplicationProgramNew app = new ApplicationProgramNew(); | |
ServiceProgramNew service = new ServiceProgramNew(); | |
OperatingSystemNew os = new OperatingSystemNew(); | |
os.start(app); | |
os.start(service); | |
} | |
} |
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
package sample.dependency.Inversion.good; | |
import java.util.List; | |
/** | |
* | |
* 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 OperatingSystemNew { | |
private List<Runner> apps; | |
public void start(Runner runner) { | |
apps.add(runner); | |
runner.run(); | |
} | |
} |
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
package sample.dependency.Inversion.good; | |
/** | |
* | |
* Distibution under GNU GENERAL PUBLIC LICENSE Version 2, June 1991 | |
* | |
* @author dmalalan | |
* @created Apr 12, 2016 2:50:38 PM | |
* | |
* @blog https://malalanayake.wordpress.com/ | |
*/ | |
public interface Runner { | |
public void run(); | |
} |
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
package sample.dependency.Inversion.good; | |
/** | |
* | |
* 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 ServiceProgramNew implements Runner { | |
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