Fluent Object Creation

When we are tasked with creating a POJO we will often fire up our favorite editor, add the attributes, and generate the accessor methods.

Here is an example of an Invoice class. For simplicity sake only a few of its many attributes will be shown.

public class Invoice {

	private InvoiceActor invoiceSupplier;
	private InvoiceActor invoiceDestination;
	private String supplierDocumentId;
	private Date documentDate;
	private String trailerNumber;
	private List<InvoiceItem> items;
	...

Given this code we would then create an instance of our Invoice and use our setters to populate the values of the attributes.

InvoiceActor supplier = new InvoiceActor();
supplier.setActorName("101");
supplier.setActorType(InvoiceActorType.DC);
...

List<InvoiceItem> list = new ArrayList<InvoiceItem>();
InvoiceItem itemOne = new InvoiceItem("TK421", 10, 8);
list.add(itemOne);
...

Invoice inv = new Invoice();
inv.setSupplierDocumentId("5150");
inv.setTrailerNumber("2112");
inv.setInvoiceSupplier(supplier);
inv.setInvoiceDestination(reciever);
inv.setItems(list);

When creating our POJO, we could add a constructor to our class that accepts the values for the various attributes so that they are initialized when the object is created. It allows us to create the object with less code than what we see above. It can also allow us to insure that our object was in a valid state at the point it is created (see Constructor Initialization for more details). And if we were going to make our Invoice class an immutable object we would need to get rid of the setters so we would typically turn to a constructor with parameters as an alternative to populate the attributes. Continue reading “Fluent Object Creation”

Advertisements

Not Just Coding Zombies

Listened to this talk by Martin Fowler, of Agile Manifesto fame. In this talk he suggests that “we as developers should not be just code monkeys bashing out code.” We developers, he suggests, need to consider the responsibility that we have for the software that is going to be written and used.

And I think that we have a certain responsibility to say: where are we going to apply our talents? Because in the end we are responsible for using our talents to, hopefully, make the world somewhat of a better place.

… we should say “is what we are doing useful?”

This reminded me of the Spiderman quote : with great power comes great responsibility. And having just read the graphic novel Marvel Zombies, led to capturing the main idea of the talk in this graphic.

codingzombies2

Continue reading “Not Just Coding Zombies”

The Agile life has been good to me so far

With apologies to Joe Walsh and all my coworkers through the years here is a little ballad about work in the IT field on this Labor Day. Read/sung to the tune “Life’s been good to me so far”.

I use open source, it has no price
I contribute back, it works so nice
Why does commercial get used at all
Costs so much bang my head ‘gainst the wall

They say I’m crazy but I have a good time
I’m just looking for bugs at the scene of the crime
Life’s been good to me so far

Our velocity was one-eighty-five
but our release plan took a nose dive
Now we limit wip, our flow is great
I check the board to find out our fate

There is a deadline, my boss he can’t wait
I’ll call my sweet wife, I’m working late
And I got me no office, cube farms have no walls
Like coding cattle sittin’ in stalls

Lucky I’m sane writing code like I do
I can’t keep up there’s always somethin’ new
Life’s been good to me so far

I write some software, it’s agile clean code
If there’s no bugs we’ll deploy on some nodes
My product owner has not a clue
We’ll bail ’em out like we always do

My mind goes hazy codin’ for all this time
I keep on writin’ pays the bills so that’s why
Life’s been good to me so far