On 2011-09-23 12:55:25 +0300, deadalnix said:

I recently faced a problem in java. I have looooooooots of classes inheriting from the same superclass. Thoses classes has to conform to some behaviour expected when manipulation the superclass as Liskov substitution principle says.

This is definitvelly hard to achieve. Solution promoted on the web are frankly not satisfying. Most of them suggest to inherit jUnit tests too, bit this is unable to handle classes implementing multiple interfaces, and require to write a test class for each subclasses. So if somebody don't do thoses tests, the subclass isn't checked (which is predictible) but the superclass tests are not ran either, which make things even worse. This innability to check that easily makes a lazy dev even more dangerous, which isn't what we want.

Back to D, which has integrated unittest, I wonder how I could implement such a check. I think the D unittest system suffer the same flaw as jUint (previously exposed). What do you think ?

deadalnix

D has a wonderful feature that is suitable for such use cases - Design By Contract. You specify invariants and in/out contracts in your superclass and they will be automatically checked for subclasses.

Read more here - http://www.d-p-l.org/dbc.html

Reply via email to