---
title: "Discussion on \"A new way to construct objects in Java\" | Hashnode"
description: "Discussion on \"A new way to construct objects in Java\". Java, Declarative Programming, Design Pattern"
url: "https://hashnode.com/posts/a-new-way-to-construct-objects-in-java/61961e0890fac127e6ea5f22"
---

[Feed](https://hashnode.com/feed) /

Discussion

# [A new way to construct objects in Java](https://nambach.hashnode.dev/a-new-way-to-construct-objects-in-java?utm_source=hashnode&utm_medium=feed)

Java, Declarative Programming, Design Pattern

Nov 18, 2021 · 5 min read · nambach.hashnode.dev  
Read the article

-   [#java](https://hashnode.com/tag/java)
-   [#functional-programming](https://hashnode.com/tag/functional-programming)
-   [#tips](https://hashnode.com/tag/tips)
-   [#design-patterns](https://hashnode.com/tag/design-patterns)

## Written by

[Nam Bach](https://hashnode.com/@nambach)

@nambach

  
[View profile](https://hashnode.com/@nambach)

Java enthusiast

## Responses 2

Markdown supported · ⌘↵ to post

[Mukund Madhav](https://hashnode.com/@mukundmadhav)

[Nov 21, 2021](https://hashnode.com/posts/a-new-way-to-construct-objects-in-java/61961e0890fac127e6ea5f22/comment/619a60c65bb9cc256fc6ad80)

Really interesting idea of mimicking Lambok. Will try this one.

[Shai Almog](https://hashnode.com/@talktotheduck)

[Nov 18, 2021](https://hashnode.com/posts/a-new-way-to-construct-objects-in-java/61961e0890fac127e6ea5f22/comment/619644750b25eb28701f5f4a)

I solved this a bit differently with property objects in Codename One. The core idea was to eliminate getters/setters and use general purpose property objects: [codenameone.com/blog/properties-are-amazing.html](https://www.codenameone.com/blog/properties-are-amazing.html)

So the code would be:

```
public class Book implements PropertyBusinessObject {
    public final Property<Book, String> isbn = new Property<>("isbn"); 
    public final Property<Book, String> title = new Property<>("title"); 
    public final Property<Book, String> author = new Property<>("author"); 
}
```

Notice I need the string names since code in Codename One is often obfuscated and I want runtime information.

Then we can create a book with a factory like this:

```
Book b = new Book()
    .author.set("Shai Almog")
    .title.set("Create an Uber Clone in 7 Days");
```

[Nam Bach](https://hashnode.com/@nambach)

[Nov 19, 2021](https://hashnode.com/posts/a-new-way-to-construct-objects-in-java/61961e0890fac127e6ea5f22/comment/619644750b25eb28701f5f4a#reply-6196fff9db238d58f5e23c4d)

Thanks for your comment, that looks great!
