Path: utzoo!utgpu!jarvis.csri.toronto.edu!rutgers!iuvax!purdue!mentor.cc.purdue.edu!gza From: gza@mentor.cc.purdue.edu (William R Burdick) Newsgroups: comp.object Subject: Re: OO Languages with "constraints" (Was: Subclassing vs. subtyping) Message-ID: Date: 22 Oct 89 03:21:00 GMT References: <33009@cornell.UUCP> <18129@pasteur.Berkeley.EDU> <18450@pasteur.Berkeley.EDU> Sender: news@mentor.cc.purdue.edu Distribution: comp Organization: Team Cthulhu Lines: 15 If you always use methods to access instance variables, you can easily implement constrained instance variables in Smalltalk & Objective-C (I don't know C++ or Eiffel). ex. if a square is a special kind of rectangle where height=width, just make the height method return 'self width', rather than height and make 'height: value' send 'self width: value' instead of setting height. You can change the accessing functions to make variables actually be functions of other variables this way. Constraints involving comparing constants (like >10) are even easier, just do type checking on the value given to 'height: value'. -- Bill -- -- Bill Burdick burdick@cello.ecn.purdue.edu