Miscellaneous questions...

Blake blake at kingdomrpg.com
Fri Sep 9 08:49:36 UTC 2005


On Thu, 08 Sep 2005 22:03:26 -0700, Alan Lovejoy  
<squeak-dev.sourcery at forum-mail.net> wrote:

> An accessor method must be justified by one of two requirements: 1) The
> value of the instance variable needs to be provided as a part of the
> object's API, or 2) the value must be lazily initialized or recomputed.
> Otherwise, an accessor is not only unnecessary, it violates the  
> information hiding principle.
>
> A mutator method must be justified by one of two requirements: 1) The  
> value of the instance variable must be settable as part of the object's  
> public API, or 2) there is an invariant that must be maintained whenever  
> the value of the instance variable is changed (e.g., a change event must  
> be
> propagated, the value of another instance variable must be recomputed,  
> etc.) Otherwise, a mutator is not only unnecessary, it violates  
> encapuslation.

Yeah, that matches my philosophy,

> Re: Global Symbols
>
> Blake>[Using global symbols] "Could make for some REALLY obscure bugs  
> under some unlikely situations...."
>
> Such as? Symbols aren't mutable. And they're flyweights.  Other than  
> that, they are subject to all the same misuses as would apply to String  
> instances, aren't they? (Your original question did suggest using  
> Strings as the
> alternative.)

Yes, pretty much. I would expect a string-confusion to come up more  
frequently, but I'd also be watching for it.<s>

Where my reticence comes from is Pascal. In Pascal, you'd have an  
enumerated type. And you could declare:

rank = (Jack, Queen, King, Ace);

in one unit and:

rank = (Pawn, Knight, Queen, King);

in another, and you wouldn't be allowed to confuse one for the other.  
You'd also have to qualify one or the other, depending on how you used  
those units (as either Cards.King or Chess.King, say).

Note that I'm not saying this is better or even good. Just that I feel  
exposed without it.<s>

> Blake>"A deck of cards IS an ordered collection of cards."
>
> Except when it's a SortedCollection of cards.  Or an Array of cards. Or a
> linked list of cards. Or... I think you get the point.

Yeah. Well, that's often the case with inheritance, innit? It's not so  
much Deck ISA OrderedCollection but Deck ISCLOSENOUGHTOA  
OrderedCollection.<s>

> Also, it's not necessarily the case that all the operations in the API of
> Collection should be supported by a deck of cards. More importantly, the
> level of abstraction and the semantics are both different.  For one  
> thing, a deck of cards should not contain numbers, Strings nor  
> Timestamps. For
> another, there is both a semantic and a behavioral distinction between  
> the object that represents the state of a particular deck of cards at a
> particular moment in a particular game and one that defines the complete  
> set of cards with which the game is played.

True, and an excellent point. This suggests that my reflext toward  
delegation is, in this case at least, justified.

I think this is a situation where Traits would have helped.



More information about the Squeak-dev mailing list