diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..549e00a --- /dev/null +++ b/.gitignore @@ -0,0 +1,33 @@ +HELP.md +target/ +!.mvn/wrapper/maven-wrapper.jar +!**/src/main/**/target/ +!**/src/test/**/target/ + +### STS ### +.apt_generated +.classpath +.factorypath +.project +.settings +.springBeans +.sts4-cache + +### IntelliJ IDEA ### +.idea +*.iws +*.iml +*.ipr + +### NetBeans ### +/nbproject/private/ +/nbbuild/ +/dist/ +/nbdist/ +/.nb-gradle/ +build/ +!**/src/main/**/build/ +!**/src/test/**/build/ + +### VS Code ### +.vscode/ diff --git a/pom.xml b/pom.xml new file mode 100644 index 0000000..1d22473 --- /dev/null +++ b/pom.xml @@ -0,0 +1,24 @@ + + + 4.0.0 + + se.nackademin.java20 + solid + 1.0-SNAPSHOT + + + + + org.apache.maven.plugins + maven-compiler-plugin + 3.5.1 + + 11 + 11 + + + + + \ No newline at end of file diff --git a/src/main/java/se/nackademin/java20/solid/_1sre/violation/Account.java b/src/main/java/se/nackademin/java20/solid/_1sre/violation/Account.java new file mode 100644 index 0000000..c8bf9d0 --- /dev/null +++ b/src/main/java/se/nackademin/java20/solid/_1sre/violation/Account.java @@ -0,0 +1,17 @@ +package se.nackademin.java20.solid._1sre.violation; + +public class Account { + private int balance; + + public Account(int balance) { + this.balance = balance; + } + + public void deposit(int money) { + this.balance += money; + } + + public void print() { + System.out.println("Current balance: " + balance); + } +} diff --git a/src/main/java/se/nackademin/java20/solid/_2ocp/violation/Validator.java b/src/main/java/se/nackademin/java20/solid/_2ocp/violation/Validator.java new file mode 100644 index 0000000..10f7a65 --- /dev/null +++ b/src/main/java/se/nackademin/java20/solid/_2ocp/violation/Validator.java @@ -0,0 +1,11 @@ +package se.nackademin.java20.solid._2ocp.violation; + +public class Validator { + + public boolean validate(int quantity) { + if (quantity < 0) return false; + if (quantity > 100) return false; + return true; + } + +} diff --git a/src/main/java/se/nackademin/java20/solid/_3lsp/violation/Rectangle.java b/src/main/java/se/nackademin/java20/solid/_3lsp/violation/Rectangle.java new file mode 100644 index 0000000..33a0f5b --- /dev/null +++ b/src/main/java/se/nackademin/java20/solid/_3lsp/violation/Rectangle.java @@ -0,0 +1,23 @@ +package se.nackademin.java20.solid._3lsp.violation; + +public class Rectangle { + private int width; + private int height; + + public Rectangle(int width, int height) { + this.width = width; + this.height = height; + } + + public void setWidth(int width) { + this.width = width; + } + + public void setHeight(int height) { + this.height = height; + } + + public int area() { + return width * height; + } +} diff --git a/src/main/java/se/nackademin/java20/solid/_3lsp/violation/Square.java b/src/main/java/se/nackademin/java20/solid/_3lsp/violation/Square.java new file mode 100644 index 0000000..a458deb --- /dev/null +++ b/src/main/java/se/nackademin/java20/solid/_3lsp/violation/Square.java @@ -0,0 +1,20 @@ +package se.nackademin.java20.solid._3lsp.violation; + +public class Square extends Rectangle { + public Square(int width, int height) { + super(width, height); + } + + @Override + public void setWidth(int width) { + super.setWidth(width); + super.setHeight(width); + } + + @Override + public void setHeight(int height) { + super.setHeight(height); + super.setWidth(height); + } + +} diff --git a/src/main/java/se/nackademin/java20/solid/_4isp/violation/Animal.java b/src/main/java/se/nackademin/java20/solid/_4isp/violation/Animal.java new file mode 100644 index 0000000..ebe1974 --- /dev/null +++ b/src/main/java/se/nackademin/java20/solid/_4isp/violation/Animal.java @@ -0,0 +1,6 @@ +package se.nackademin.java20.solid._4isp.violation; + +public interface Animal { + void run(); + void jump(); +} diff --git a/src/main/java/se/nackademin/java20/solid/_4isp/violation/Elephant.java b/src/main/java/se/nackademin/java20/solid/_4isp/violation/Elephant.java new file mode 100644 index 0000000..c89505b --- /dev/null +++ b/src/main/java/se/nackademin/java20/solid/_4isp/violation/Elephant.java @@ -0,0 +1,14 @@ +package se.nackademin.java20.solid._4isp.violation; + +public class Elephant implements Animal { + @Override + public void run() { + System.out.println("I am running super fast!"); + } + + @Override + public void jump() { + throw new UnsupportedOperationException("I cannot jump!"); + + } +} diff --git a/src/main/java/se/nackademin/java20/solid/_4isp/violation/Tiger.java b/src/main/java/se/nackademin/java20/solid/_4isp/violation/Tiger.java new file mode 100644 index 0000000..b6efbcc --- /dev/null +++ b/src/main/java/se/nackademin/java20/solid/_4isp/violation/Tiger.java @@ -0,0 +1,14 @@ +package se.nackademin.java20.solid._4isp.violation; + +public class Tiger implements Animal { + @Override + public void run() { + System.out.println("Like the speed of light!"); + } + + @Override + public void jump() { + System.out.println("Jumping highest of them all!"); + + } +} diff --git a/src/main/java/se/nackademin/java20/solid/_5dip/violation/ConsolePrinter.java b/src/main/java/se/nackademin/java20/solid/_5dip/violation/ConsolePrinter.java new file mode 100644 index 0000000..5b944a5 --- /dev/null +++ b/src/main/java/se/nackademin/java20/solid/_5dip/violation/ConsolePrinter.java @@ -0,0 +1,7 @@ +package se.nackademin.java20.solid._5dip.violation; + +public class ConsolePrinter { + void print(String text) { + System.out.println(text); + } +} diff --git a/src/main/java/se/nackademin/java20/solid/_5dip/violation/TextPrinter.java b/src/main/java/se/nackademin/java20/solid/_5dip/violation/TextPrinter.java new file mode 100644 index 0000000..104afe1 --- /dev/null +++ b/src/main/java/se/nackademin/java20/solid/_5dip/violation/TextPrinter.java @@ -0,0 +1,13 @@ +package se.nackademin.java20.solid._5dip.violation; + +public class TextPrinter { + private final ConsolePrinter consolePrinter; + + public TextPrinter(ConsolePrinter consolePrinter) { + this.consolePrinter = consolePrinter; + } + + public void print(String text) { + consolePrinter.print(text); + } +}