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.
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community