A
A
Alexey Nikolaev2017-09-03 01:41:17
PHP
Alexey Nikolaev, 2017-09-03 01:41:17

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

1 answer(s)
D
DevMan, 2017-09-03
@Heian

kagbe traits and created for code reuse.
the rest is a matter of personal preferences and religious beliefs.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question