cocoon-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Upayavira ...@upaya.co.uk>
Subject Re: Scriptable objects with BeanShell
Date Mon, 24 Nov 2003 21:02:54 GMT
Bertrand Delacretaz wrote:

> Le Lundi, 24 nov 2003, à 21:05 Europe/Zurich, Upayavira a écrit :
>
>> ...From looking at the BeanShell docs, the Java is definitely 
>> 'scripted' java, and lacks Java's object orientedness...
>
>
> But what about this example from the BeanShell docs:
>
> buttonHandler = new ActionListener() {
>     actionPerformed( event ) {
>         print(event);
>     }
> };
>
> button = new JButton();
> button.addActionListener( buttonHandler );
> frame(button);
>
> A new behaviour for ActionListener is indeed created in a script.
> Isn't this a good example of object orientedness, do you have a 
> counterexample?

Yup. But I can't code a class called User, and then invoke it with 'new 
User()', I have to do it inline.

I guess I could do:

newUser() {
    user = new Object() {
        setUsername(username) {
            this.username = username;
         }
         validatePassword(password) {
         ...etc
     }
}

And then do:
myUser = newUser();
myUser.setUsername("upayavira");
if (myUser.validatePassword("xyz")) {
  cocoon.sendPage(".....");
} else {
   ...
}

Then I've effectively created a class. But it seems a bit around the 
houses to me.

Regards, Upayavira


Mime
View raw message