Re: What are first-class objects?
From: Sergei Gnezdov (sergei-gnezdov-pub_at_pobox.com)
Date: 12/19/03
- Next message: Randy A. Ynchausti: "Re: OO Progress Metrics?"
- Previous message: Val: "Re: Prototype, Class F, & Abstract Factory [Was: Phil, in here please.]"
- In reply to: Guy: "Re: What are first-class objects?"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Fri, 19 Dec 2003 01:57:27 GMT
Thanks. I suspected that the reality was the way you put it, but I
could not describe it as well myself.
I really like the definition of the first class objects.
On Thu, 18 Dec 2003 06:35:51 GMT, "Guy"
<gmarremoveentette@neo.rrremovetoo.com> wrote:
>
>Let me try.
>
><Sergei Gnezdov> wrote in message
>news:b4eb43ff74fa0603dd4238c0105298a6@news.teranews.com...
>> What is the definition of the first-clas object?
>
>A first-class object is something for which you can invoke a method to get a
>result.
>
>>
>> Are Classes first-class objects in C# and Java?
>
>Classes in Java are not first-class objects. They are compiler directives
>that are activated using an operator (new) to create an instance of that
>class.
>
>But when the Java compiler is presented with a class definition, it also
>generates an object of the class Class, and links this object with each
>instance object of that class. This provides Java's reflection capability,
>i.e. the ability to interrogate an object for some of its properties such as
>supported methods and encapsulated data types.
>
>I don't know about C#, but suspect it's similar to Java.
>
>Contrast that with Smalltalk. In Smalltalk, classes are first-class objects.
>Instances of a class are created by invoking a method in the class object
>(in Smalltalk, you send a message to the object to invoke a method). Most
>often, but not always, the message sent to the class object is #new. One can
>also, like Java, use the class objects to find properties of the instances.
>
>>
>> The following web page caused me to ask the question:
>>
>http://www.fh-konstanz.de/studium/ze/cim/projekte/osefa/patterns/abfact/implem.htm
>> with the phrase in it "A variation on the Prototype-based approach is
>> possible in languages that treat classes as first-class objects
>> (Smalltalk and Objective C, for example)."
>>
>> The was a code sample similar to:
>>
>> factoryMethod: classAssociation
>> ^(associationsDictionary at: classAssociation) new
>>
>>
>> Thank you.
>
>So in this example, (associationsDictionary at: classAssociation) is
>returning a class object and that object is then being sent the #new message
>which will return an instance of that class.
>
>Had this been Java, you couldn't just simply adapt to the different syntax
>by moving the #new message so it becomes an operator something like this:
>
> return new associationsDictionary.getAt(classAssociation);
>
>Instead, you would need to either code the actual class, including the
>arguments for the desired constructor (which defeats the intended purpose
>here) or use the dictionary to access an appropriate factory object which
>can be sent a message to generate the required object.
>
- Next message: Randy A. Ynchausti: "Re: OO Progress Metrics?"
- Previous message: Val: "Re: Prototype, Class F, & Abstract Factory [Was: Phil, in here please.]"
- In reply to: Guy: "Re: What are first-class objects?"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|