update solid ex
This commit is contained in:
@@ -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);
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user