Support the ongoing development of Laravel.io →
Architecture
Last updated 1 year ago.
0

It is always a good design to have a class with one (and only one) responsibility. This is called Single Responsibility Principle (SRP). The ThreadCreator, manages the validation of Threads if it is a spam or not. The ThreadCreatorListener is responsible for what action must took place when an error occured or when created successfully. ThreadCreatorlistener is 'injected' to the ThreadCreator's create() method. And since ThreadCreator only knows how to validate a Thread, it will ask the implementation of ThreadCreatorListener of what action should took place.

If, in future, you wish to add a new algorithm to check if the Thread is valid, you know where to go: ThreadCreator. Or if you want a different way to handle the errors, just create a new class that implements the ThreadCreatorListener interface

DISCLAIMER: I don't exactly know what those codes you provide does. But I hope you get the idea.

0

Sign in to participate in this thread!

Eventy

Your banner here too?

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2024 Laravel.io - All rights reserved.