Me wrote: > > > > PRE and POST are to support OO Design-By-Contract ala Bertrand Meyers >> > My question is, why are blocks like FIRST not inherited? So, since you've read the book on design by contract, you know that PRE and POST _ARE_ inherited because they enforce preconditions, postconditions, and invariants that are to be true before and after the execution of a particular conceptual operation implemented by an object method. The fact that an object has been subclassed, and additional modifications made to extend the method for different situation should have no impact on the validity of properly written pre- and post-conditions, so inheriting them enforces that, without requiring the pre- and post-conditions to be rewritten to apply to each of the derived methods individually. That being said, blocks like FIRST, NEXT, LAST, and CATCH have nothing to do with design by contract, nothing to do with object orientation, and are just an expressive language syntax to allow concise, accurate programs to be written more easily. The FIRST (NEXT, LAST, CATCH) blocks from a method may be completely inappropriate for use in any of its derived methods, there are no design rules that say that the should, or benefits of encouraging that they are, in spite of the fact that design by contract supplies both for PRE and POST blocks. So PRE and POST blocks are there for design by contract, which specifies inheritance of them for derived methods. The other blocks are there for other uses, and inheriting them has no universal benefit. Where such a benefit might exist, a subroutine with appropriate parameters could be written, so that the appropriate logic could be shared between different derived method implementations. Consider a method containing an assignment statement $x = $y; It is quite possible that a derived method may also assign $x the value from $y. However, it is equally possible that it might not. You wouldn't suggest that assignment statements should be inherited to derived methods, however.... or would you? In any case, a FIRST block is just another statement to be used in the implementation of surrounding blocks, some of which are methods, and there is simply no impetus to have them be inherited. Whereas PRE and POST blocks are specifically being included to support design by contract, and inheritance is very appropriate for that special use, when they are used in object methods. -- Glenn ===== Due to the current economic situation, the light at the end of the tunnel will be turned off until further notice.Thread Previous | Thread Next