Search code examples
oopmodel-view-controllerbusiness-logicseparation-of-concerns

Business logic that needs to be reused, where should I placed it?


I have business logic like this that I need to reuse. My business logic is ordered like this:

User.Save();  
Payroll.Calculate();  
Mailer.Send();  

Currently it's in my controller, but I want it to use in another controller. Where should I place that business logic and if there's design pattern what is it?

Sorry for noob question.


Solution

  • Use Application Service for such logic as plalx suggests. Good explanation of different options for designing application services you can find in the last chapter of the follwoing book: https://www.amazon.com/Implementing-Domain-Driven-Design-Vaughn-Vernon/dp/0321834577

    I would suggest also to look at hexagonal architecture: http://alistair.cockburn.us/Hexagonal+architecture