# Auto-subclassing/Factory question

**URL:** <https://www.ruby-forum.com/t/auto-subclassing-factory-question/124817>\
**Category:** Rails\
**Created:** [January 2, 2008, 9:08pm UTC](https://www.ruby-forum.com/t/auto-subclassing-factory-question/124817 "2008-01-02T21:08:34Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![MonkeyLice](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/8e7dd6/32.png) [@MonkeyLice](https://www.ruby-forum.com/u/MonkeyLice)\
**Post date:** [January 2, 2008, 9:08pm UTC](https://www.ruby-forum.com/t/auto-subclassing-factory-question/124817/1 "2008-01-02T21:08:34Z")

</div>

I’ve got an application that tracks different types of Tasks and the  
differing tasks have subclasses like PersonalTask and WorkTask. These  
are stored in the database along with their “type” (type is a column  
in the database). This allows things like:

p = new PersonalTask(“Go shopping”)  
p.save  
w = new WorkTask(“File Reports”)  
w.save  
all = Task.find(:all)  
print "First task is of type ", all[0].type.to\_s

# Prints #\<PersonalTask:0x70000000 @attributes{“name”=\>“Go shopping”,

“type”=\>“PersonalTask”, …}  
print "Second task of type ", all[1].type.to\_s

# Prints #\<WorkTask:0x70000000 @attributes{“name”=\>“File Reports”,

“type”=\>“WorkTask”, …}

Notice how the type of the object is preserved. Nifty, except use of  
“type” is deprecated and it should now be “class”. Unfortunately this  
trick doesn’t work when you change “type” to “class” as a column in  
the DB. Since this will completely break when “type” really goes away  
I was wondering what people suggest as a replacement given there are  
~8 types. I’d hate to have to create a factory method the knows about  
all the types since that seems a little inelegant compared to the auto-  
subclassing I have now.
