Answer the question
In order to leave comments, you need to log in
Are traits an antipattern?
Goodnight.
I'll start with a specific task: there are two functions that, in fact, add certain categories to the record entity, modifying them (the record id is passed to them, they modify the record and save the changes to the database). Previously, these were private methods in one class, but now it was necessary to use these functions in another place, and I do not see a better way to do this than to put them in a trait. You can, of course, put it in a class, but how to call a class that does nothing, but only stores two functions? All other classes are divided according to their tasks, but here the task is vague, so I see the trait as the most semantic option.
At the same time, a class that uses a trait is less transparent, so the question is: is it even worth using traits as small libraries of self-contained functions? Is it possible to do better without traits?
Thanks in advance.
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question