So far I have a number of things which I don't like.
When using this, we cannot do:
- Abstract classes are evil.It indicates base classes, but inheritance should never be used for code reuse. Use interfaces, factories, strategies for such stuff. Moreover, they give code that cannot be tested (easily)
- final should not be used, except to designate constant statics. Nothing more, as it is superfluous take-space-on-my-screen crap
- Builders which cannot be extended. Ideally, a builder should be separate from the value object, and the value object should be extensible. Hence, private constructors are a no-go for the value-object. The disadvantage of using builders is that it is hard to extend them properly, as they are usually not templated and thus do not use a proper signature. E.g.
class OldBuilder {
int a;
OldBuilder withInt(int a ) {
this.a=a;
return this;
}
ValueObject build() {
return new ValueObject(this);
}
}
class NewBuilder extends OldBuilder {
String b;
NewBuilder withString(b) {
this.b=b;
return this;
}
@Override
NewValueObject build() {
return new NewValueObject(this);
}
}
When using this, we cannot do:
new NewBuilder().withInt(12).withString("hello").build();
Since withInt() returns an OldBuilder, which does not have the method withString(). Annoying
(although really, method chaining doesn't make me happy anyway)
(although really, method chaining doesn't make me happy anyway)
Reacties
Een reactie posten