[comp.object] OO Languages with "constraints"

cline@sun.soe.clarkson.edu (Marshall Cline) (10/15/89)

In article <18129@pasteur.Berkeley.EDU> hws@icsib1.Berkeley.EDU (Heinz Schmidt) writes:
>I believe at the heart of OO programming is the understanding that
>instance variables, in general, are *not* independent.  In general 
>a method will operate on a couple of variables. ...

Ok.  So you're saying there (typically) is redundant information in a
class.  The key then is that the "methods" keep this redundant
information coherent ("self consistent"?).

>... In the above setting you might say, a SQUARE
>is a rectangle with the constraint
>		 HEIGHT=WIDTH 
>(some OO languages allow to express such constraints)....
  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
What languages?

What you seem to be saying is: The self-consistency of the redundant
information in a class can be formally specified in "some OO languages."
But one of the cries at OOPSLA'89 was the need to support this kind of
semantic information in our OO Languages.  No one said "Language X does a
great job at this kind of thing," so I wonder which languages you're
refering to.

Actually this point is more than just idle chatter to me.  Indeed this
very question is at the heart of current research I'm doing with Doug
Lea (dl@oswego.oswego.edu).  I appreciate the pointers.
Marshall
--
	__________________________________________________________________
	Marshall P. Cline	Internet: cline@sun.soe.clarkson.edu
	225 Clarkson Hall	Alternate:bh0w@clutx.clarkson.edu
	ECE dept		Usenet:   uunet!sun.soe.clarkson.edu!cline
	Clarkson University	Bitnet:   BH0W@CLUTX
	Potsdam, NY  13676	AT&T:     315-268-3868

hws@icsib1.Berkeley.EDU (Heinz Schmidt) (10/17/89)

In article <CLINE.89Oct14182152@sun.clarkson.edu>,
cline@sun.soe.clarkson.edu (Marshall Cline) writes:
...
> >              HEIGHT=WIDTH
> >(some OO languages allow to express such constraints)....
> What languages?
...
>But one of the cries at OOPSLA'89 was the need to support this kind of
>semantic information in our OO Languages.  No one said "Language X does

In Eiffel, you write the constraint as a class invariant [B.  Meyer:
Object-oriented Software Construction, Prentice Hall, 88].  You would
have to implement it, though, but the system can do some checking.

In OBJ2, an executable OO specification language, you can express
equational constraints.  [Principles of OBJ2, Conf. Rec.  12-th ACM
Symp. POPL 85, pp.52--66; there is also a more recent techrep., don't
have the reference at hand, it goes something like Goguen et al:
Introduction to OBJ2, SRI, Menlo Park, CA, 88?]

You might also want to have a closer look at OO logic programming
languages where classes are sets of facts (recent posting in this
group about ObjVProlog-D, for instance.) As I have limited experience
with PROLOG only, I can figure that one adds clausal constraints
easily.

-- Heinz Schmidt  (hws@icsi.berkeley.edu)

gza@mentor.cc.purdue.edu (William R Burdick) (10/22/89)

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

render@m.cs.uiuc.edu (10/25/89)

Written 10:21 pm  Oct 21, 1989 by gza@mentor.cc.purdue.edu:
>If you always use methods to access instance variables, you can easily
>implement constrained instance variables in Smalltalk & Objective-C.

Yeah, but it's nice to make constraints declarative (i.e. height=width)
and have those things maintained automatically rather than encoding the
verification procedures by hand.  I think some relational DMBSs provide
this facility, and it's an interesting idea for OO PLs and DBMSs.

ebm@ibmarc.uucp (Eli Messinger) (10/27/89)

A good example of integrating a constraint system into an OOL is Alan
Borning's "ThingLab", built on/in Smalltalk-80.  See:

	Borning, Alan, "The Programming Language Aspects of
	ThingLab, A Constraint-Oriented Simulation Laboratory."
	ACM Transactions on Programming Languages and Systems,
	3(4):353-387, October 1981.

	Borning, Alan and Robert Duisberg, "Constraint-Based
	Tools for Building User Interfaces."  ACM Transactions
	on Graphics 5(4), October 1986.

	Borning, Alan, et al. "Constraint Hierarchies."  In
	Proceedings of the 1987 ACM Conference on Object-Oriented
	Programming Systems, Languages and Applications, pp. 48-60,
	October 1987.

	Freeman-Benson, Bjorn, "Constraint Imperative Programming:
	A Research Proposal."  Universit of Washington, Computer
	Science Dept. Technical Report #89-04-06, June 1989.

In article <77500008@m.cs.uiuc.edu> render@m.cs.uiuc.edu writes:
> 
> Written 10:21 pm  Oct 21, 1989 by gza@mentor.cc.purdue.edu:
> >If you always use methods to access instance variables, you can easily
> >implement constrained instance variables in Smalltalk & Objective-C.
> 
> Yeah, but it's nice to make constraints declarative (i.e. height=width)
> and have those things maintained automatically rather than encoding the
> verification procedures by hand.  I think some relational DMBSs provide
> this facility, and it's an interesting idea for OO PLs and DBMSs.


--
 "The real test of an artist, of course, is not whether you can see each blade
 of grass, but whether the eyes follow you across the room."   --Stewart Evans

  CSNET: ebm@ibm.com / UUCP: ...!uunet!ibmarc!ebm / BITNET: ebm@almvma.bitnet