I'm not pulling this out of my head. This is what I have had to work with, albeit simplified. Let's say that basically you have a program that needs an enum:
enum {
a, b, c;
} myenum;
But instead what we have is
HashTable t;
t["a"] = 0;
t["b"] = 1;
t["c"] = 2;
But of course, no implementation of a hash table is good enough so there is a local implementation of hash tables, which contains about 10 times more code than an average open source implementation with half the features and double the number of bugs. The HashTable is actually defined virtual, and there's a factory HashTableFactory to create instances of HashTables, but true to the pattern HashTableFactory is also virtual. To prevent an infite cascade of virtual classes there's a function
HashTableFactory *makeHashTableFactor();
Thus everywhere where the code needs myenum's it carries a reference to the instance of a HashTable and HashTableFactory, in case you want to make more HashTable's. But wait, that's not all! This is not how the hash table is initialized, but it's done by writing a code that reads XML:
and inserts into a hash table. But the code is "optimised" so that it doesn't read an ascii file myenum.xml, but instead there's a compile time script which generates:
const char* myenumXML = [13, 32, 53 ....];
from myenum.xml and the hash table is initialized by a function:
void xmlToHashTable(char *xml, HashTable *h, HashTableFactory *f);
which is called:
HashTableFactory *factory = makeHashTableFactory();
HashTable *t = facotry.make();
xmlToHashTable(myenumXML, t, f);
Ok, so we have a lot of code to get an enum structure. It's basically used in a function:
void printStuff(int c) {
switch (c) {
case a: print("a");
case b: print("b");
case c: print("c");
}
}
and this is called in a context where:
void stuff(char* str) {
int c = charToEnum(str);
printStuff(c);
}
So what we actually have is instead of
void stuff(char *str) {
printf(str);
}
we have manged to generate thousands of lines of code (private new, buggy, complex, implementation of hashtables, and xml readers, and writer) in place of the above 3.