Skip to content

Commit

Permalink
Add solid voilations
Browse files Browse the repository at this point in the history
  • Loading branch information
daneidmark committed Aug 23, 2021
0 parents commit a961c27
Show file tree
Hide file tree
Showing 11 changed files with 182 additions and 0 deletions.
33 changes: 33 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -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/
24 changes: 24 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>se.nackademin.java20</groupId>
<artifactId>solid</artifactId>
<version>1.0-SNAPSHOT</version>

<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.5.1</version>
<configuration>
<source>11</source>
<target>11</target>
</configuration>
</plugin>
</plugins>
</build>
</project>
Original file line number Diff line number Diff line change
@@ -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);
}
}
Original file line number Diff line number Diff line change
@@ -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;
}

}
Original file line number Diff line number Diff line change
@@ -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;
}
}
Original file line number Diff line number Diff line change
@@ -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);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package se.nackademin.java20.solid._4isp.violation;

public interface Animal {
void run();
void jump();
}
Original file line number Diff line number Diff line change
@@ -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!");

}
}
Original file line number Diff line number Diff line change
@@ -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!");

}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package se.nackademin.java20.solid._5dip.violation;

public class ConsolePrinter {
void print(String text) {
System.out.println(text);
}
}
Original file line number Diff line number Diff line change
@@ -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);
}
}

0 comments on commit a961c27

Please sign in to comment.