I'm designing the speculative cargo code.
I don't want it to be too clever, but I need it to handle the rules.
I think building the cargo is easy, and in fact it seems like a CargoBuilder is in order here. Let me give you an example.
Speculative cargo in Traveller is sold based on the source world's trade codes, and potentially other modifiers (like whether or not a broker is available and contracted for example). If I packed all of this into a constructor, it would be a big honking constructor. On the other hand, a Builder pattern lets me chunk construction into e.g. chained methods ("fluent interface").
In fact, I should be doing this with world data, ship data, and player data as well, but I currently don't.
Of course it won't work that way. It will iterate over trade code strings.
I could just hand the trade codes in a string to the builder.
I don't want it to be too clever, but I need it to handle the rules.
I think building the cargo is easy, and in fact it seems like a CargoBuilder is in order here. Let me give you an example.
Speculative cargo in Traveller is sold based on the source world's trade codes, and potentially other modifiers (like whether or not a broker is available and contracted for example). If I packed all of this into a constructor, it would be a big honking constructor. On the other hand, a Builder pattern lets me chunk construction into e.g. chained methods ("fluent interface").
Code:
Cargo cargo = CargoBuilder.newCargo().isNa().isRi().build();
In fact, I should be doing this with world data, ship data, and player data as well, but I currently don't.
Of course it won't work that way. It will iterate over trade code strings.
I could just hand the trade codes in a string to the builder.
Code:
Cargo cargo = CargoBuilder.build( "Na Ni Po De" );
Last edited: