[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: What's so cool about Scheme?



["Bayley, Alistair" <Alistair_Bayley@ldn.invesco.com>]
> 
> > I think of OO as being the ability to provide user-defined types with
> invariants
> 
> I'm not sure what "invariants" are (but I do know that use-defined types
> are). Is it possible to have "user-defined types with invariants" in a
> language that would not be considered object-oriented (Modula, Pascal, C,
> ML)?
> 

I suppose the poster was referring to what's usually called encapsulation,
in that OO design practices encourage us to create objects that have
some state, but that state is only mutable through a set of operations
that the object chooses to expose. In this sense, these operations can
enforce any invariants they'd like on the internal state of the object.

Certainly non-OO languages offer facilities to do this, in the form of
modules (in the non-ML sense) with explicit exports and controlled access,
abstypes in ML, modules (in the ML sense) which can actually be
instantiated in a way similar to OO objects, and I'm sure there are
many others. So this definitely isn't an OO-only feature, but I think
many languages could really improve their support for this.

Matt

-- 
Matt Hellige                  matt@immute.net
http://matt.immute.net