Re: [matrix][cssom-view] DOMPoint, DOMPointLiteral definitions

On Sat, Sep 28, 2013 at 10:24 AM, Robert O'Callahan <robert@ocallahan.org>wrote:

> You need to read up more about that. What I have proposed is exactly what
> that principle would suggest.
>

(Sorry about being terse, it's the weekend here and I had things to do.)

In that proposal, a DOMRect has a current x/y/width/height, provides
read-only access to that state, and some other useful read-only
functionality defined in terms of that state (e.g. right/bottom). It offers
no way to mutate the state, and says nothing about whether the state is
immutable or not.

A DOMRectImmutable extends DOMRect with the invariant that the state never
changes. It is Liskov-Wing substitutable for a DOMRect, because all clients
can do with a DOMRect is read the current state, and that works on a
DOMRectImmutable. All invariants that a DOMRect satisfies are also
satisfied by DOMRectImmutable.

A DOMRectMutable extends DOMRect with methods to modify the current state.
It too is Liskov-Wing substitutable for a DOMRect.

I know this can be a little confusing, but it's totally OK for a
LW-substitutable subclass to offer invariants that the superclass doesn't
offer. The reverse is forbidden (since a client could rely on such an
invariant in the superclass and be broken when the subclass is substituted).

In "Square extends Rectangle", this is actually OK if the Rectangle
interface doesn't expose mutability. It fails when the Rectangle interface
lets you mutate width and height independently. It fails because Rectangle
then offers an invariant that Square can't offer --- namely, that after you
set "width" to W and "height" to H, then reading "width" will give you W
and reading "height" will give you H, for all non-negative W and H.

Rob
-- 
Jtehsauts  tshaei dS,o n" Wohfy  Mdaon  yhoaus  eanuttehrotraiitny  eovni
le atrhtohu gthot sf oirng iyvoeu rs ihnesa.r"t sS?o  Whhei csha iids  teoa
stiheer :p atroa lsyazye,d  'mYaonu,r  "sGients  uapr,e  tfaokreg iyvoeunr,
'm aotr  atnod  sgaoy ,h o'mGee.t"  uTph eann dt hwea lmka'n?  gBoutt  uIp
waanndt  wyeonut  thoo mken.o w  *
*

Received on Saturday, 28 September 2013 11:20:56 UTC