What a waste of time today has been - so depressed!! Just tried implementing "Replace Type Code With Subclass" pattern (Martin Fowler) - on my code and it just made it worse - so in light of this I am going to try and ask you guys what I perhaps should have done.
I have a treeview with custom nodes I am adding to it. I have created 3 classes, (one inheriting TreeNode).
1 class in pretty generic (the one that inherits Treenode), the other 2 inherit this class with some peculiarities of their own.
I make an object of one of 3 types as and when necessary and add to the treeview. No problem here as they all have a base TreeNode.
When comes the time to iterate through the nodes I have problems in code elegance - I keep having to query the object to see what type it is - this causes a lot of switch/case statements everywhere and will only get worse the more custom nodes I add over time (requirements change as we all know!) - so what patterns should I be looking at? How can I make my code more easier to maintain - I just know it can be so much better (grrrrr!)
Any help much appreciated
Regards
I have a treeview with custom nodes I am adding to it. I have created 3 classes, (one inheriting TreeNode).
1 class in pretty generic (the one that inherits Treenode), the other 2 inherit this class with some peculiarities of their own.
I make an object of one of 3 types as and when necessary and add to the treeview. No problem here as they all have a base TreeNode.
When comes the time to iterate through the nodes I have problems in code elegance - I keep having to query the object to see what type it is - this causes a lot of switch/case statements everywhere and will only get worse the more custom nodes I add over time (requirements change as we all know!) - so what patterns should I be looking at? How can I make my code more easier to maintain - I just know it can be so much better (grrrrr!)
Any help much appreciated
Regards