F
F
Flasher2017-10-16 11:50:14
symfony
Flasher, 2017-10-16 11:50:14

Am I doing it right that I put everything except working with the database into separate classes and then implement it as DI?

Am I doing it right that I put everything except working with the database into separate classes and then implement it as DI? For example: uploading images, processing graphics, etc. If not correct, then what should be taken out into separate classes and then used as Dependency Injection. Thank you.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
E
eRKa, 2017-10-16
@kttotto

All these DI, IoC were invented for loose coupling. Those. their use is justified if you want to break a strong dependency between some modules or objects, because expect changes in the future or want to add the ability to test some section of the code.
If neither one nor the other is important to you, then you should not bring it to fanaticism)
And by the way, if they want unit testability, then the dependence on the database is torn first of all. Otherwise, you will get integration tests that depend on the data in the database. Well, if in the future it is assumed that they want to switch to another database, then in this case, too, it is advisable to move work with it into abstraction and then inject it.

S
Sergey, 2017-10-16
@red-barbarian

You should read this about clean architecture.
It is possible to approach from such considerations a class that is easily tested is already done correctly.
What should be tested in the classroom? Only the logic that we wrote. Strictly speaking, we supply stub objects as input and test only our own logic.
This approach is consistent with the Single Responsibility Principle, that a class only does its own thing.
Applying DI correctly, you get this division: components - independent reusable parts and assemblers - those who assemble the components into the desired system and configuration.
You will get clarity and reusability. Plus flexibility.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question