Some Rare but Invaluable Java Patterns 🧵 1) Null Object Pattern Avoid null checks by using a no-op object that implements expected behavior. It keeps code clean by avoiding conditionals around method calls (e.g., if (obj != null) everywhere). Use when returning null leads…
                                            2) Parameter Object Pattern Bundle related parameters into a single object. You can pass the parameter object around different layers, ensuring consistency. Use when methods have too many related args.
                                                    3) Fluent Interface / Method Chaining Chain method calls for better readability. Communicates intent clearly (especially in builder-like objects). Use in builders or config-style setups.
                                                    4) Execute Around Method Pattern Abstract setup/teardown around an operation. Prevents resource leaks by always handling teardown properly. Use for resource management (e.g. opening/closing files/DB).
                                                    5. Initialization-on-Demand Holder (a variant of Singleton) Lazy-load a singleton safely without synchronized. Use when you want performant, thread-safe singleton.
                                                    Use no-op objects with caution as they just pretend to be real values. But they do not. In your sample, NullPayment::pay(), does nothing but the payment processor thinks the payment is completed. It 's better to use Optionals in most of the cases...
IMHO, somehow we must know if an object is null to know how we should proceed.
At line # 5, it doesn't avoid a conditional; only it is transformed, but not avoided. In certain cases, I think is necessary to check if an object is null; so, conditionals couldn't be avoided.
                                                    Bro... this is just hard to watch. Just use Kotlin already.
United States Tendances
- 1. Cowboys 68.7K posts
 - 2. Nick Smith 14.3K posts
 - 3. Kawhi 4,329 posts
 - 4. Cardinals 30.8K posts
 - 5. #LakeShow 3,411 posts
 - 6. #WWERaw 62K posts
 - 7. Jerry 45.3K posts
 - 8. Kyler 8,445 posts
 - 9. Blazers 7,951 posts
 - 10. Jonathan Bailey 22.9K posts
 - 11. Logan Paul 10.2K posts
 - 12. No Luka 3,589 posts
 - 13. #WeTVAlwaysMore2026 211K posts
 - 14. Jacoby Brissett 5,607 posts
 - 15. Valka 4,843 posts
 - 16. Cuomo 175K posts
 - 17. Pickens 6,666 posts
 - 18. Dalex 2,537 posts
 - 19. Bronny 14.8K posts
 - 20. Pacers 12.8K posts
 
Something went wrong.
Something went wrong.