R
Roy Smith
Nick Craig-Wood said:I didn't say it wasn't useful, just that if you came from Perl like I
did, it is an easy mistake to make ;-)
Agreed.
OO lore says whenever you see a type field in an instance you've gone
wrong - types should be represented by what sort of object you've got,
not by a type field.
OO lore lives in an ivory tower sometimes
system, where objects are marshaled on the wire as type codes followed by a
type-specific number of bytes of data. Internally, it calls these AnyVals
and the concept is pervasive in the architecture. I could work within the
existing architecture, or I could try to fight it.
Yes, I could get rid of the dispatch table and create 20 or 30 classes to
represent all the possible types. I'd end up with several times as much
code, most of it boilerplate. Instead of having a dispatch table of
read/write functions, I'd have a dispatch table of classes, each of which
has a read method and a write method. It doesn't buy anything, and I'd
still have the type codes exposed because I need them to read and write
values to the wire.