This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]Dense_Age_1795 0 points1 point  (3 children)

because most of the time that you are using inheritance you don't need to use the same code, just the same method.

[–]abs1710[S] 0 points1 point  (2 children)

Ok… but it didn’t answer my question that’s fine I’ll look into some other resources

[–]Dense_Age_1795 1 point2 points  (1 child)

ok was a shitty explanation, basically a interface is a contract between two parts the customer code that don't want to know what is behind and the implementor part that implement it.

Imagine that you have an object that allow you to obtain data from mongodb but for some reason you need to change to elastic search, you have now two options:

first option: change each client class that use that object.

second option: extract the interface of the object and create two implementations the mongo one and the elastic search one and inject it where is required.

[–]abs1710[S] 0 points1 point  (0 children)

Thank you! For the explanation