So, I am now dealing with this relatively new codebase which uses, and sometimes feels like it abuses traits. Since I have been exposed to trait usage in a rather limited fashion, I was wondering whether the way they are using them makes sense. I believe they are preferring to use traits when good old inheritance would work just as well.
Here is an example of what I am talking about:
trait CrudTrait
{
use FindTrait;
use ExistsTrait;
use UpdateTrait;
}
Then, the trait is used more or less the following fashion:
class <EntityName>ServiceAbstract extends ServiceAbstract
{
use CrudTrait;
}
I can't think of a reason why something like this is necessarily better than just making such methods class members. At the end of the day, these particular traits are designed in such a way that they cannot be re-used horizontally.
Is there any reason why this could better than just attaching the methods to the parent class of the hierarchy?. I am starting to believe that trait abuse could be a code smell here.