Back in an engineering position, I come across newly written #Java code that has a lot of improvement potential regarding maintainability. It works, but I imagine engineers having to update it, including the original author’s future self and me, and I’m sure I can help them. This week, I refactored code using creational #DesignPatterns. In this post, I want to describe the issues I faced and mention how patterns helped me.

My thoughts on object creation.

https://blog.frankel.ch/thoughts-object-creation/

#GoF #OOP

Thoughts on object creation

Creational patterns were first described in the famous Gang of Four’s Design Patterns. The book presents each pattern in a dedicated chapter and follows a strict structure for each one: intent, motivation, applicability, structure, participants, collaborations, consequences, implementation, sample codes, known uses, and related patterns. The intent pattern presents a succinct goal of the pattern, while the applicability tells when you should use it. For example, here’s an excerpt fo

A Java geek

@frankel

"Creating the builder code is a pain (unless you use AI)"

For the love of god, please do not use AI for such a trivial use case. Your IDE will gladly generate the code for you. See

- https://www.jetbrains.com/help/idea/replace-constructor-with-builder.html

- or if you want an inner class https://stackoverflow.com/questions/10348491/builder-pattern-code-generation-in-intellij/35144261#35144261
-- there is also a plugin

- or use Lombok

Replace constructor with builder | IntelliJ IDEA

IntelliJ IDEA Help
@ghost_letters There was a time I was a fan of Lombok. But the glamour of the novelty quickly faded when confronted with the pain of setting a compile-time annotation processor.

@frankel

It is simpler to use AI then to use Lombok? Maybe AI can configure the annotation processor?

I mean, looks like the other options I mentioned are right off the table.

@ghost_letters I wrote everything by hand. Does it make you happier?

@frankel

I know you are asking this as an rhetorical question, but for the sake of the argument: no, it does not make me happier.

Options that would make me happier:

- tell me why AI is better in your experience then the options I mentioned. I am happy to learn from your experience
OR
- accepting that these non-AI options might be equal or better than AI here

Probably there are more options that would work for making me happy.

@ghost_letters I mentioned AI because the Builder code is boilerplate code, which AI (or IDE, I don't care) is good at generating.

It's funny, because on /r/java/, a guy tells me I should generate objects with AI and I'm the one pushing back (and getting down voted to hell) 🤦‍♂️

@frankel

Probably this "guy" is an AI itself. 😆

@ghost_letters I wish, but only real people can be so pig-headed 😅