DEV Community

Discussion on: Turn Your Spaghetti Code into Functions - Part 3

Collapse
 
monknomo profile image
Gunnar Gissel

You certainly could use the decorator pattern with the validation. I'm not sure how it would play with the functional approach, but it would be interesting to take for a test drive and see.

Another pattern I thought of trying out is the chained filter pattern in the Validator class. I think that could give some richer possibilities for linking business rules together.

If I were doing this for real, I would have the related functions all in one empty class, and the methods like checkWidgetTransfer in a different class, yes. I've found functional Java tends to collect a couple classes that are empty except for functions, which felt weird at first, but where else are you going to put them?