Skip to content
This repository has been archived by the owner on Feb 1, 2022. It is now read-only.

Liskov Principle #1

Open
jaimepizarr opened this issue Jul 12, 2020 · 0 comments
Open

Liskov Principle #1

jaimepizarr opened this issue Jul 12, 2020 · 0 comments

Comments

@jaimepizarr
Copy link

DataStore Interface
https://github.com/axhixh/cacofonix/blob/master/src/main/java/gaul/cacofonix/store/Datastore.java
H2Datastore Class
https://github.com/axhixh/cacofonix/blob/master/src/main/java/gaul/cacofonix/store/H2Datastore.javaç
MemoryDatastore Class
https://github.com/axhixh/cacofonix/blob/master/src/main/java/gaul/cacofonix/store/MemoryDatastore.java

We can see that there's a violation on the Liskov Principle from SOLID because the close method is used in H2DataStore to close the connection with the DB, but it is not used in the MemoryDatastore class. I mean, this is a behaviour that is not shared by the MemoryDatastore class. Therefore, we can see that this method shouldn't be at the Datastore Interface.

You can make another interface called DataStoreDB where you can have the close method and extends from the DataStore interface. Then you can implement the DataStore Interface on the MemoryDataStore class and implement the DataStoreDB Interface on the H2DataStore Interface.

(Recomendation made for educational purposes)

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant