Re: Entity and Identity
Date: Mon, 27 Jul 2009 23:35:39 -0700 (PDT)
On Jul 28, 1:21 am, rp_at_raampje.(none) (Reinier Post) wrote:
> Nilone wrote:
> >On Jul 25, 10:34 am, Nilone <rea..._at_gmail.com> wrote:
> >> OO classes are used to create data types, since encapsulation,
> >> constructors and attributes are necessary features to create data
> >> types. However, it fails as a type system since it allows subtypes to
> >> be defined that breaks the original type. It also allows for the
> >> creation of reference types, which is an oxymoron.
> >I mean mutable types, not reference types.
> Aren't those problems caused by the use of mutability
> rather than OO inheritance? Of course subtypes can break
> the original type, but developers aren't supposed to do that.
> What alternative to inheritance do you propose for sharing
> function implementations across objects of different but related types,
> and how is it any safer?
Types define values. Values aren't mutable, since mutability implies a persistent identity beyond the value itself. As soon as you have mutability, you have a state machine, and subtyping state machines is a problem. Subtyping an interface and creating a new state machine for it is fine.
According to this, subtyping is possible for values (the R usage envelope) and single-user state machines (the S envelope). Since classes are reference types, single-user state machines can't be assumed. As such, I don't consider subtyping of state machines to be viable. Behavioural subtyping is an active research field, but I'm not aware of a general solution yet.
If you need the same functions in different state machines, create an instance of the base machine and use its function, or create a function library which can be used by both. Received on Tue Jul 28 2009 - 08:35:39 CEST