Reputation: 4420
In my project I have several services. Example UserService, ArticleService, LogService and so on. Each service contains functions to create, read, updade, delete, etc. Now the question. When I need to add an item to the User, I use UserService. This, in turn, need to create an object in the log. Should UserService create a new instance of the LogService and use this feature. Or should UserService create this object?
Upvotes: 0
Views: 36
Reputation: 322
UserService should be aware of some LoggerServiceInterface and should not be aware of it's concrete implementation - LoggerService in your case. LoggerService object should implement LoggerServiceInterface and must be injected into UserService via constructor or setter. I believe you should check out some Dependency Injection Container implemented in your programming language.
Upvotes: 1