Dienstag, 9. Februar 2010

Design by Contract in Spring Roo

In Spring Roo they use a simple approach for Design by Contract (ok not real DBC only preconditions), looks nice for me here a code snippet from Spring Roo source code:

public MailProtocol(String protocolLabel, String protocol) {
 Assert.notNull(protocolLabel, "Protocol label required");
 Assert.notNull(protocol, "protocol required");
...
public AbstractInvocableMemberMetadata(String declaredByMetadataId, int modifier, List parameters, List parameterNames, List annotations, String body) {
 Assert.hasText(declaredByMetadataId, "Declared by metadata ID required");
... 

I think the Spring Roo way is a good hint for Design by Contract / Preconditions as tests in Java, which is not support native in the Java language. The Java asserts can be disabled the spring roo Asserts throws RuntimeExceptions...

Other Java Framework for Design by Contract:
Links:
Languages, which support real Design by Contract: