W
Wolf
Say I have the following XML (as example)
<root>
<foo type="num">10</foo>
<foo type="date">2006-10-10</foo>
</root>
I now want to create at run-time a foo object but specifically a
specialisation of it based on the value of the "type" attribute (i.e.
some arbritary value).
What I do currently is,
foo f = null;
if (type == "num"){
f = new fooNum();
}
else if (type == "date"{
f = new fooDate();
}
but...... is there a cleaner way .. more OO?
Can I have some nice way of creating the right subClass based on the
value of the "type" attribute. The XML is just for example but really
what I'm looking for is the correct way of creating subClasses depending
on some condition so that you dont end up using big switch statements!
Ta in advance
<root>
<foo type="num">10</foo>
<foo type="date">2006-10-10</foo>
</root>
I now want to create at run-time a foo object but specifically a
specialisation of it based on the value of the "type" attribute (i.e.
some arbritary value).
What I do currently is,
foo f = null;
if (type == "num"){
f = new fooNum();
}
else if (type == "date"{
f = new fooDate();
}
but...... is there a cleaner way .. more OO?
Can I have some nice way of creating the right subClass based on the
value of the "type" attribute. The XML is just for example but really
what I'm looking for is the correct way of creating subClasses depending
on some condition so that you dont end up using big switch statements!
Ta in advance
