This commit is contained in:
Jonathan Cook
2019-10-23 15:01:44 +02:00
parent db85c8f275
commit 684ec0d2e3
20486 changed files with 1642483 additions and 0 deletions
+5
View File
@@ -0,0 +1,5 @@
### Relevant Articles:
- [A Solid Guide to Solid Principles](https://www.baeldung.com/solid-principles)
+18
View File
@@ -0,0 +1,18 @@
<?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>com.baeldung</groupId>
<artifactId>solid</artifactId>
<name>solid</name>
<version>1.0-SNAPSHOT</version>
<parent>
<groupId>com.baeldung</groupId>
<artifactId>patterns</artifactId>
<version>1.0.0-SNAPSHOT</version>
<relativePath>..</relativePath>
</parent>
</project>
@@ -0,0 +1,4 @@
package com.baeldung.d;
public interface Keyboard {
}
@@ -0,0 +1,6 @@
package com.baeldung.d;
public class Monitor {
}
@@ -0,0 +1,5 @@
package com.baeldung.d;
public class StandardKeyboard implements Keyboard {
}
@@ -0,0 +1,15 @@
package com.baeldung.d;
public class Windows98Machine {
private final StandardKeyboard keyboard;
private final Monitor monitor;
public Windows98Machine() {
monitor = new Monitor();
keyboard = new StandardKeyboard();
}
}
@@ -0,0 +1,12 @@
package com.baeldung.d;
public class Windows98MachineDI {
private final Keyboard keyboard;
private final Monitor monitor;
public Windows98MachineDI(Keyboard keyboard, Monitor monitor) {
this.keyboard = keyboard;
this.monitor = monitor;
}
}
@@ -0,0 +1,12 @@
package com.baeldung.i;
public class BearCarer implements BearCleaner, BearFeeder {
public void washTheBear() {
//I think we missed a spot..
}
public void feedTheBear() {
//Tuna tuesdays..
}
}
@@ -0,0 +1,5 @@
package com.baeldung.i;
public interface BearCleaner {
void washTheBear();
}
@@ -0,0 +1,5 @@
package com.baeldung.i;
public interface BearFeeder {
void feedTheBear();
}
@@ -0,0 +1,9 @@
package com.baeldung.i;
public interface BearKeeper {
void washTheBear();
void feedTheBear();
void petTheBear();
}
@@ -0,0 +1,5 @@
package com.baeldung.i;
public interface BearPetter {
void petTheBear();
}
@@ -0,0 +1,8 @@
package com.baeldung.i;
public class CrazyPerson implements BearPetter {
public void petTheBear() {
//Good luck with that!
}
}
@@ -0,0 +1,8 @@
package com.baeldung.l;
public interface Car {
void turnOnEngine();
void accelerate();
}
@@ -0,0 +1,12 @@
package com.baeldung.l;
public class ElectricCar implements Car {
public void turnOnEngine() {
throw new AssertionError("I don't have an engine!");
}
public void accelerate() {
//this acceleration is crazy!
}
}
@@ -0,0 +1,13 @@
package com.baeldung.l;
public class Engine {
public void on(){
//vroom.
}
public void powerOn(int amount){
//do something
}
}
@@ -0,0 +1,18 @@
package com.baeldung.l;
public class MotorCar implements Car {
private Engine engine;
//Constructors, getters + setters
public void turnOnEngine() {
//turn on the engine!
engine.on();
}
public void accelerate() {
//move forward!
engine.powerOn(1000);
}
}
@@ -0,0 +1,10 @@
package com.baeldung.o;
public class Guitar {
private String make;
private String model;
private int volume;
//Constructors, getters & setters
}
@@ -0,0 +1,9 @@
package com.baeldung.o;
public class SuperCoolGuitarWithFlames extends Guitar {
private String flameColour;
//constructor, getters + setters
}
@@ -0,0 +1,27 @@
package com.baeldung.s;
public class BadBook {
private String name;
private String author;
private String text;
//constructor, getters and setters
//methods that directly relate to the book properties
public String replaceWordInText(String word){
return text.replaceAll(word, text);
}
public boolean isWordInText(String word){
return text.contains(word);
}
//methods for outputting text to console - should this really be here?
void printTextToConsole(){
//our code for formatting and printing the text
}
}
@@ -0,0 +1,13 @@
package com.baeldung.s;
public class BookPrinter {
//methods for outputting text
void printTextToConsole(String text){
//our code for formatting and printing the text
}
void printTextToAnotherMedium(String text){
//code for writing to any other location..
}
}
@@ -0,0 +1,20 @@
package com.baeldung.s;
public class GoodBook {
private String name;
private String author;
private String text;
//constructor, getters and setters
//methods that directly relate to the book properties
public String replaceWordInText(String word){
return text.replaceAll(word, text);
}
public boolean isWordInText(String word){
return text.contains(word);
}
}