I've been mucking about a bit more with this whole interface thing.

So if we make method signatures only enforced on subclasses if the parent
class or method has the interface property...

....except private methods, obviously.

And if we make pre/post conditions and class invariants always enforced...

....shouldn't we have private invariants and conditions?


    class Car is interface {
          attr wheels;      
          invar { .wheels == 4 }
          
          method accel($how_fast);
          method turn($direction, $how_sharp);
    }
    
    class ATV is Car, interface {
          attr _tilt is private;
          invar { ._tilt <= 20 } is private;
          
          method turn($direction, $how_sharp) {
                     pre  { $how_sharp <= 20 } is private;
                     ...implementation...
          }
    }

I've implemented an ATV where I've put in a saftey protection against
rolling over in a turn as both an invariant and a pre-condition.  It will
not allow you to turn the car too sharply, else it simply blows up.  Wait
second... ;)

But I don't want my subclasses to be constrained by that.  It's just an
implementation detail that I only wish to enforce upon ATV and not it's
children.  So they're private.

Makes sense, no?


-- 

Michael G. Schwern   <[EMAIL PROTECTED]>    http://www.pobox.com/~schwern/
Perl Quality Assurance      <[EMAIL PROTECTED]>         Kwalitee Is Job One
Remember, any tool can be the right tool.
    -- Red Green

Reply via email to