A
A
Alexey Nikolaev2018-01-05 23:19:54
Programming
Alexey Nikolaev, 2018-01-05 23:19:54

Is it good practice to make interfaces even when the class is not going to be replaced?

Goodnight.
It's about the 2nd and 5th principles of SOLID. For example, I have class A, which is guaranteed to be alone in the program, and it turns out that the classes that use it depend on details, and not on abstractions (after all, class A does not have an interface - why should it, if there is only one class). In addition, class A is specifically designed to be a bridge between lower abstraction classes that may already be replaced.
Is it worth striving for full compliance with these principles, creating an interface even if it is guaranteed to be implemented only once?
Thanks in advance.

Answer the question

In order to leave comments, you need to log in

4 answer(s)
E
eRKa, 2018-01-06
@Heian

No, don't. No need to complicate the project where it is not required.
There is a rule of the first bullet: at first you write as simply as possible and only when the first changes come that require abstraction, then only you highlight it.

I
ImSorry, 2018-01-06
@ImSorry

This article is well written when you need an interface and why you need
it
project.

S
Sergey, 2018-01-06
@red-barbarian

the inversion principle is the coolest principle.
development starts from the head. Those. if your task is to design a program, then you start building it from the most important thing - its business logic. You will not know which entities the logic will use. It will come from the process. Therefore, everything that the business logic needs you define by interfaces.
In this case, it will turn out, breaking down the logic and the entities that serve it.
due to the fact that the first one changes quickly and often (for various reasons, even beyond the control of the developer), this partition is very useful. The main thing is that you can give the development of the service to other people, we are not aware of the libraries that will be used (and can change from), we can easily test our logic.
More or less like this.
Interfaces are good to use at the boundaries of program layers. This enables testing and partitioning.

M
Maxim Fedorov, 2018-01-05
@Maksclub

Abstraction is evil, but a necessary evil ... if there is no need, then ...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question