Answer the question
In order to leave comments, you need to log in
That is, I can’t get away from the double code?
Trouble looks something like this.
There is a controller for buying and selling, it has two actions to buy and sell.
There is a controller of the so-called introductory location, in which you must definitely try to make a purchase and sale, there is a control of actions, therefore, if you do not go through the introductory location, then there is no access to the purchase and sale controller.
Since there is no access to the buy and sell controller until the familiarization has passed :), then it cannot be used for this very familiarization)))
It turns out that for the familiarization location I need to stupidly rewrite the code from the buy and sell controller into its controller, right?
Answer the question
In order to leave comments, you need to log in
No, not correct. Duplication is evil. At one point, you can forget that you have a purchase in two places. Fix one, forget the other.
You need to create some kind of service where you can take out this logic. For example OrderService . It will have methods to buy and sell. You connect this service to the controller. And call from the controller. As a result, you can have a bunch of controllers and actions that work with one service.
Use inheritance. Let your buy and sell controller be inherited from some base deal controller, and the test deals controller also be inherited from the base controller. You take out all the common code in the base controller and you don’t need to rewrite anything.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question