Re: Clean Object Class Design -- Circle/Ellipse

From: James A. Robertson <jarober_at_mail.com>
Date: Mon, 08 Oct 2001 12:18:24 GMT
Message-ID: <3BC199E9.8020103_at_mail.com>


Use one I'm actually likely to stumble on in a real application I might write.

Bob Badour wrote:

> Using the real example of circle and ellipse:
> 
> How does Smalltalk:
> *   allow me to declare circle as a subtype of ellipse?


I subclass Circle from Ellipse

> * allow me to send the setFoci message to ellipse variables (that > incidentally contain circle values) with two different focal points?

I override the methods in the subclass so that each gets appropriate behavior. If the ellipse variable contain circle values, ,my application code is wrong>

> * prevent me from sending the setFoci message to circle variables?

See above.

If I find that I'm overriding enough methods, subclassing was a bad choice. You have created an example 'problem' that isn't much of a problem.

> 
> "James A. Robertson" <jarober_at_mail.com> wrote in message
> news:3BBFDD8E.4020802_at_mail.com...
> 

>>Using a real example, show me how any of your points matter in Smalltalk.
>>
>>
>>Bob Badour wrote:
>>
>>
>>>brangdon_at_cix.co.uk (Dave Harris) wrote in message
>>>
> news:<memo.20011001000009.35593A_at_brangdon.madasafish.com>...
> 

>>>>bbadour_at_golden.net (Bob Badour) wrote (abridged):
>>>>
>>>>
>>>>>Ask him to point to any Smalltalk language definition that defines
>>>>>"instance" as anything other than a variable which one can reference.
>>>>>
>>>>>
>>>>The 1997 draft of the ANSI Smalltalk standard (which is the version of
>>>>
> the
> 

>>>>standard I have to hand), says:
>>>>
>>>> A /variable/ is a computational entity that stores a single
>>>> reference (the /value/ of the variable) to an object.
>>>>
>>>> [...] An /object/ is a computational entity which is capable of
>>>> responding to a well defined set of messages. An object may
>>>> also encapsulate some (possibly mutable) state.
>>>>
>>>>This is *not* saying an object is a variable.
>>>>
>>>>
>>>"reference to an object" implies that "object" is variable. Values are
>>>self-identifying and one cannot reference a value. One can reference
>>>storage or memory that contains some representation of a value, but
>>>storage and memory are variable. That a variable is constrained to a
>>>single value for some period of time does not change its nature.
>>>
>>>That's not to say that no such thing as an object value exists. Object
>>>value is an important concept just as object variable is an important
>>>concept.
>>>
>>>If you had included a little more from the standard where it defines
>>>/message send/ and explains that "Each argument is a reference to an
>>>object", you would see that Smalltalk requires a variable in order to
>>>send a message. In other words, Smalltalk only pretends to have values
>>>and requires one to store a representation of a value in a variable
>>>prior to doing anything.
>>>
>>>
>>>
>>>
>>>>(The ANSI standard does not define "instance". It uses "object" instead.
>>>>Later it says that when an object does have state, it represents it with
>>>>special kind of variables called "instance variables". In other words,
>>>>
> an
> 

>>>>object is not a variable but an object can contain variables.)
>>>>
>>>>
>>>How does one change part of something that cannot change?
>>>
>>>
>>>
>>>
>>>>>An instance or variable can have the value 5. The value, however, is
>>>>>not an instance.
>>>>>
>>>>>
>>>>So sorry, but in Smalltalk the value 5 is an instance of the class
>>>>SmallInteger.
>>>>
>>>>
>>>Untrue. An instance of the class SmallInteger can contain a
>>>representation of the value 5, but the value 5 is not an instance of
>>>anything. I realize that Smalltalk confuses things by requiring
>>>variables for messaging and then pretending that variables are values.
>>>
>>>
>>>
>>>
>>>>>One cannot reference a value. Values are self-identifying.
>>>>>
>>>>>
>>>>Indeed 5 is self-identifying. We can send a message to the value 5
>>>>
> whether
> 

>>>>or not we have a variable referring to it.
>>>>
>>>>
>>>Yes, I agree that one can have operations on values. These are, of
>>>course, different from update operations on variables. Have you not
>>>seen me state that previously? Of course, the Smalltalk standard
>>>requires all implementations to operate only on variables.
>>>
>>>
>>>
>>>
>>>>>According to the definition of the Smalltalk language an instance is a
>>>>>variable that one can reference.
>>>>>
>>>>>
>>>>Again, so sorry, but my reading of the ANSI definition of Smalltalk says
>>>>that an instance (or object) is something which responds to messages.
>>>>
>>>>
>>>My reading of the same says that one can reference an instance (or
>>>object), which means it must have some physical existence. Variables
>>>have physical existence where each stores some representation of a
>>>value; values have no physical existence. Values exist regardless of
>>>physical representation.
>>>
>>>
>>>
>>>
>>>>Perhaps you are talking about some other language, also called
>>>>
> Smalltalk?
> 

>>>No. I just read with a little extra care and a little better
>>>understanding of the concepts involved.
>>>
>>>
>>>
>>>
>>>>How confusing! Can you point me to a definition of your language?
>>>>
>>>>
>>>The one above definition will suffice. You should also read section
>>>3.3.2 very carefully.
>>>
>>>
>>>
>>>
>>>>Definitions of ANSI Smalltalk are available from:
>>>> http://minnow.cc.gatech.edu/squeak/172
>>>>
>>>> Dave Harris, Nottingham, UK | "Weave a circle round him thrice,
>>>> brangdon_at_cix.co.uk | And close your eyes with holy dread,
>>>> | For he on honey dew hath fed
>>>>http://www.bhresearch.co.uk/ | And drunk the milk of Paradise."
>>>>
>>>>
>
> Received on Mon Oct 08 2001 - 14:18:24 CEST

Original text of this message