K
K
Kirill Gorelov2020-06-02 21:56:42
PHP
Kirill Gorelov, 2020-06-02 21:56:42

What pattern can replace a trait?

Hi guys.
Got a question.
What mono pattern to replace traits with?
It's not that it's bad, no, I'm only interested in informational purposes.

I went through the cheat sheet on patterns https://refactoring.guru/en/design-patterns/php, but I didn’t find something to replace directly or I wasn’t looking for it ....

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
Maksim Fedorov, 2020-06-02
@Maksclub

On the question: There is such a pattern as "behaviors", an analogue of mixin / trait - it is not designated as a pattern in books, since it is not in books.
This implementation is in the Yii2 framework. Brief overview of the pattern:
https://rmcreative.ru/blog/post/mixin-v-php
But traits are better :)
If you consider that you want to get rid of inheritance, then this is not really about patterns, but about principles and architecture, to building abstractions. And the patterns will be as a result

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question