Generic Template Delegate
I think that I talked about it before, but I really loves the new abilities that Generics & Anonymous Delegates gives me. I find myself writing API that takes delegates, and it's a pleasure to work with.
It's not only property indexers and NHibernate Generics, it's a whole different way of thinking. I think that we will see a lot more code that is written to take advantage of this features.
Generic Template Delegate is a great pattern to seperate concerns, and it's very nearly delerative coding, in my opinion. Some people are worried that Linq and C# 3 will be too hard for some programmers to grok. I don't think so, I think that by the time that C# 3 is out there will be plenty of APIs out there that would make use of Generic Template Delegates.
Case in point, I had code that needed to iterate over an object graph and extract some information from it. The code is not overly complex, but it's very well broken and it's clear what is going on. Then I needed to the same iteration, but extract different information. I just moved the information extraction functionality to a delegate and created another method that call the iteration logic, extracting the information that I wanted. The whole thing was ~5 lines of code, and the refactoring took 3 minutes.
In .Net 1.1, I would have to do some heavy wieght stuff to avoid code duplication. Add an interface, implement it in two classes, etc. Oh, I could have used delegates, but that would probably not occur to me, and even then I would still need to add a delegate, write two methods, etc.
Generics & Anonymous Delegates just open up a whole new world of programming in .Net*
*And before somebody jump and say "Smalltalk/Lisp/Whatever had it X decades ago", I know that. That is partly the reason I'm so excited.
Comments
Comment preview