logo       

Disussion on creating a new class: msg#00236

Subject: Disussion on creating a new class
Hi All

I'd like to discuss on the way of creating a new class in smalltalk in
general... I hope I'll be clear enough... :) When I first start, I
found the way of creating classes not that straightforward... Probably
because this implies a minimum understanding of smalltalk...

So, here is the template to create a class when having a browser
opened on a selected category:

Object subclass: #NameOfSubclass
    instanceVariableNames: ''
    classVariableNames: ''
    poolDictionaries: ''
    category: 'Kernel-Objects'

so, the class Object (more precisely the class class) receives the message :
Class>>subclass:instanceVariableNames:classVariableNams:poolDictionaries:category:
and uses a ClassBuilder that will return the newly created class.

Some things bothers me:

*******  if we want to create a class in a selected category, we
change #NameOfSubclass in the symbol #NewNameClass
using a symbol is not obvious (for me)... I'd prefer something like:

NewClass
               subclassOf: aClass ; --> (Superclass)
               instanceVariableNames: '' ;
               classVariableNames: '' ;
               poolDictionaries: '' ;
               category: 'KernelTests-Methods' ;
               yourself

But NewClass is not (yet) an object, and it's interesting to see how
smalltalk consider it.. actually this is nothing, and smalltalk detect
it while parsing the evaluated text selection ... it is varName (a
string from the selection) in the following message to Parser:

Parser>> variable
  | varName varStart varEnd |
  varStart _ self startOfNextToken + requestorOffset.
  ***varName _ self advance.***
  varEnd _ self endOfLastToken + requestorOffset.
  ^ encoder encodeVariable: varName
        sourceRange: (varStart to: varEnd)
        ifUnknown: [self correctVariable: varName interval: (varStart
to: varEnd)]

What I'd like is to be able to create from an UnknowObject (that could
be a subclass of UndefinedObject ? would it be problematic,
interesting ?)

nb: There is actually a way to create a class from the execution of an
unknown text selection. Excuting   NewTerm   (do-it)  opens a menu
that gives the possibility to create a new class (this only works if
the selection start with an uppercase and it's done before excuting by
the parser).

******** Also, if we want to subclass a given class (which is
frequent) it's not direct as we need to change in the template the
receiver into the given class and the first argument of
#subclass:instanceVariableNames:.... in the symbol #NewNameClass.

Yet, It exists a more straight way to do that by right clicking on a
selected class in the browser and then choosing 'new class'. And so it
changes the template and wait for us to accept once proper parameters
are entered...

nb: I think 'new subclass' should be more appropriate? - new class
should only allow to create a subclass of object.

******** Last, I think that when created, the symbol with the name
should be instead directly the class...Not so easy to figure out from
what we see... Something like:

SequenceableCollection subclass: OrderedCollection --> (the class, not
the symbol)
      instanceVariableNames: 'array firstIndex lastIndex'
      classVariableNames: ''
      poolDictionaries: ''
      category: 'Collections-Sequenceable'

or:
OrderedCollection subclassOf: SequenceableCollection  ...


An interesting (long) method for class creation is:
ClassBuilder>>name:inEnvironment:subclassOf:type:instanceVariableNames:
classVariableNames:poolDictionaries:category:unsafe:

**********************************************************************************************
So I hope you understood what I've tried to say :)

If you have any comments or remarks concerning all that, I'll
appreciate having others opinions.

To sum up:
- using an UnknownObject (and especially UnknownObject>>subclassOf: aClass)
- replacing symbols with appropriate classes when possible (when
viewing a class definition)...


Thanks and see you ;)

Cédrick
_______________________________________________
Beginners mailing list
Beginners@xxxxxxxxxxxxxxxxxxxxxxxxxx
http://lists.squeakfoundation.org/mailman/listinfo/beginners
<Prev in Thread] Current Thread [Next in Thread>
Google Custom Search

Recently Viewed:
linux.arklinux....    user-groups.lin...    kde.usability/2...    ietf.ipp/2002-0...    mail.spam.spamc...    os.netbsd.devel...    audio.cd-record...    text.unicode.de...    php.documentati...    games.fps.halfl...    window-managers...    suse.oracle.gen...    bug-tracking.gn...    video.dvdrip.us...    xfree86.cvs/200...    java.netbeans.m...    network.argus/2...    culture.sf.kill...    debian.ports.al...    freebsd.questio...    qplus.devel/200...    handhelds.palm....   
Home | blog view | USPTO Patent Archive | advertise | OSDir is an inevitable website. super tiny logo

Free Magazines

Cisco News
Receive a free quarterly e-newsletter with exclusive articles on how Cisco IT uses its own products and solutions to enable the business.
subscribe

Systems Management News, the newspaper for IT systems administration and data center managers! Each issue of Systems Management News is chock-full of news and analysis to help you understand what's happening in your field.
subscribe

The Enterprise Newsweekly eWeek is the essential technology information source for builders of e-business.
subscribe

Oracle Magazine Oracle Magazine contains technology strategy articles, sample code, tips, Oracle and partner news, how to articles for developers and DBAs, and more. Oracle (NASDAQ: ORCL) is the world's largest enterprise software company.
subscribe

Total Telecom Total Telecom is "The Economist of the communications industry".
subscribe