[racket] Choosing what class to instantiate at runtime

From: Matthias Felleisen (matthias at ccs.neu.edu)
Date: Wed Jun 27 12:52:13 EDT 2012

On Jun 27, 2012, at 12:39 PM, Kieron Hardy wrote:

> Thanks Danny, that's a step in the direction I wanted to go.
> 
> But on further reflection, I think what I was looking for (i.e. have some class that stops it's own instantiation and defers to another class depending on some parameter value(s)) doesn't really make sense. Instead I need some sort of factory function that contains the conditionals and that returns an instance of the right class.
> 
> Cheers,
> 
> Kieron


That's the correct way to parameterize instantiation, but Danny's conditional will play a role there: 

  (define (factory x)
    (new (if (is-this-tuesday?) class-for-tuesday class-for-all-other-days)
         [time x]))




Posted on the users mailing list.