Decorator Design Pattern in Laravel and PHP
HTML-код
- Опубликовано: 11 июл 2024
- Learn how to implement the decorator design pattern in Laravel and PHP.
Let's discuss the benefits and the pros of using such a pattern.
Socials:
/ nick_escobedo
#decoratordesignpattern #php #laravel #designpatterns #designpatternsinphp Наука
This is so useful to have in mind when having different design patterns for certain use cases. Thanks a lot!
Appreciate the kind words, thank you for your support!
you can write this with pipeline. pipeline is very clean
The WordCountDecorator doesn't actually output $text, aside from that, pretty cool video to explain Decorators.
I don't follow. The decorator doesn't output anything because because the echo outputs the text to screen. The decorator only manipulates the string and returns it.
@@esco_tech the last decorator only returns the word count and not the entire original string reformatted by the decorator. You missed that you should have the original string and three formatted strings in the test output and there is only three plus the word count.
@@yannlescouarnec9814 Ahhh I see it now. Thank you! :)
Is this really a suitable example of a decorator design pattern? I mean, you tried to apply the decorator design pattern by the way of pipeline design pattern.
Decorator seems very verbose, why wouldn't we have trim, mention and wordcount function enclosing a string. e.g echo trim_func(mention_func(wordCount_func($originalString))); These functions can also be tested separately
share the github repo
I don't have a repo at the moment, but that's a good idea. I'll potentially incorporate that in the future.