I have an upload method that may have different kinds of implementations (Switched to another different image service).
I use that method on different controllers that needs it. I'm not sure if it's Service Container I need or a Trait and be consistent as it can't have an interface or just a simple class.
Generally, when should I use what?
-- EDIT --
I am currently trying to refactor my code to follow the DRY principle. Finding myself repeating the upload method everywhere. I currently use Tinify (laravel package for tinify).
The upload method currently does:
- Get the source file (from the input)
- Sets how the image should look like (Resized or cropped) and its dimensions.
- Actual saving where.
Am I over DRY-ing here? Even if I do, that's just a simple case/example. I still need a rule of thumb/guideline on when to use what?
When is it generally acceptable to use Classes only (with/without interfaces)? Traits? Or a Service Container?
It's not only the upload I'll be using this obviously and that's why I need answers.
-- EDIT --
I am not sure what's still not clear here, but all I am asking is:
When should I use what? I know we can do same stuffs on any of the three, but for sure there's a proper one out of the three.