tell me how the software should *behave*, not how the behavior was *implemented*
ie. describe the changes in this commit from the behavioral perspective rather than implementation details
What is the project behavior, in this snapshot?
What did the programmers, in order to produce this snapshot?
which also aligns well with the 'micro goal' or incremental deliverables approaches of most agile methodologies
helps to focus a goal to be reached
Without preemptive comments, I often went on coding, always asking myself: “Should I commit now? Have I reached a stable state which I could consider a good commit?“
but don’t know how those dependencies are instantiated
And you shouldn’t really care, all that is important is that UserService depends on dao and webservice object.
BDD template given-when-then) tests are easy to read
@Entity
public class User
calling new User(“someName”,”somePassowrd”, “someOtherName”, “someOtherPassword”) becomes hardly readable and maintainable
code duplication
Maintaining this code would turn into a nightmare in no time
running the code above will throw an exception by the JPA provider,
since not-nullable password field was never set.
Joshua Blooch gives fine example of builder pattern.
Instead of making the desired object directly, the client calls a constructor (or static factory) with all of the required parameters and gets a builder object. Then the client calls setter-like methods on the builder object to set each optional parameter of interest. Finally, the client calls a parameterless build method to generate the object, which is immutable. The builder is a static member class of the class it builds.
Coffee
public static class Builder
Builder(CoffeeType type, int cupSize)
Builder withMilk()
Coffee build()
Coffee(this)
private Coffee(Builder builder)
Coffee coffee = new Coffee.Builder(CoffeeType.Expresso, 3).withMilk().build();2}
especially if most of those parameters are optional.
For all entity attributes I create private fields
those that are obligatory become parameters for the public constructor
parameter-less constructor, I create one, but I give him
ie. never? ;)
though then, you end up with 5,932 unread emails in your inbox and 113 angry co-workers!
To combat such interruption, check these tools 3 times a day – when you first get into the office in the morning, around lunch, and before going home for the night – and turn them off otherwise.