I'm new to Smalltalk and come from the java world and am looking for a bit of 
help on how something should be implemented.


Assume I have a Person class

and that there are three subclasses of that class Admin, Teacher, Student. 

I also have a class called UserManager

I want to implement a method on UserManger>> class  firstPageForUser: user

This method looks at the class of the user and returns an initial page for each 
user after log in.

I have this method implmented:
Person>>class firstPageForUser

        ^nil


Now on the UserManager clas>> firstPageForUser: user

        (user isKindOf: Person ) ifTrue: [returnPage := ( (user class) 
firstPageForUser) ].


Which as I'm sure most of you realize doesn't work.  I'm not sure how to 
structure the call so 
that the right message gets sent to the class. 

My understanding is that even though the subclasses don't implement this method 
yet, 
that the method should be passed up the class tree till it finds the method in 
Person.

However, I also know that the syntax for the method I've written isn't correct.

What I want to do is make the call on the class for each subclass. 

I could do the same thing this way, right, but this seems more verbose and ugly 
then it has to be. 



        (user isKindOf: RSPerson ) ifTrue: [returnPage := (RSPerson 
firstPageForUserClass) ].
        (user isKindOf: RSAdmin ) ifTrue: [returnPage := (RSAdmin 
firstPageForUserClass) ].
        (user isKindOf: RSTeacher ) ifTrue: [returnPage := (RSTeacher 
firstPageForUserClass) ].
        (user isKindOf: RSStudent ) ifTrue: [returnPage := (RSStudent 
firstPageForUserClass) ].

        ^returnPage



_______________________________________________
Pharo-users mailing list
[email protected]
http://lists.gforge.inria.fr/cgi-bin/mailman/listinfo/pharo-users

Reply via email to