I am currently wrestling around with some GUI code where I have a table whose rows correspond to some object, let's say a Person object. When the table initializes, it fills the table with the Person objects that it knows about - say Bob, Andy, and Tom. The rest of the rows item's (row.getItem()
) are null. In this particular GUI framework, one cannot highlight/select rows who's getItem()
returns null - but in my particular use case I want to allow this functionality.
Therefore, upon initializing the table, I want to set the rows after Bob, Andy, and Tom to a Person object that represents a empty/null Person (not initialized per se), hence the null object pattern coming into play. The patterns combine because the Person class uses the fluent builder pattern for constructing Person instances, so I thought about combining the two like so:
for (rows in table) {
if (row.getItem() == null) {
row.setItem( Person.PersonBuilder().nullObject().build() );
}
}
I am looking for feedback/advice on the merits of this choice, and am welcome to alternatives if this approach is flawed.