Part of the keyboard clique

c# 2.0 is nice, but there’s feature creep too

December 5, 2005 · 1 Comment

Feature creep killed C++ for me and for many people. It also killed Perl for us in the same way. So I when I looked up the new features on C# 2.0, the first thing on my mind was feature creep. And sadly I saw it.

I like the way they’ve done gererics. I like the new iterator features. I like the new containers, these are very cool! I like anonymous functions. I suspect that I won’t use it too heavily, but I believe that the feature is needed. In the case of iterators and anonymous functions, I appreciate the syntax. They’ve taken care to keep the syntax intuitive and consistent with the C# look and feel.

But I don’t take to partial classes so well. I see in it a striking resemblance to the #include keyword in C and C++. To my mind it would only help when you need to split up a large class into multiple files. When would you need to do this?

Sometimes a class just keeps growing, and you don’t realize it since you are adding to it a little at a time. One day you step back, and discover that you have a very large class. Maybe 25 to 30 methods there, and this is a lot for a class that defines business logic. I would say it’s too much. I have seen such situations. Usually, the methods in such a class can be grouped into categories. For example there may be methods named addUser, modifyUser, changePassword, deleteUser, that belong together. Somehow they have all come up in the same class. I’d say that these methods need to be refactored into another class, which clearly defines user-related responsibilities.

But another approach could be to refactor the file itself; to split the class into many files, where each file holds a group of related methods. It organizes the methods. It helps gives them context. The partial classes feature is ideally suited for this. But this approach is very procedural. It cheaply relieves the pains of a large class, but fails to improve how my code represents the system. So in my view, partial classes weakens the strong object oriented capabilities of C#.

I’ve expressed a strong opinion on this subject, but I am open to hearing your ideas. If you chance upon this post, please share your perspective with me in comments.

Categories: C# · Programming · code

1 response so far ↓

  • Makinde Folasade // October 9, 2007 at 8:01 pm | Reply

    i need more knowledge about ATM encapsulation the programing languge use to develop it and how one can go abuot it. i need materials on this iwant to use it for my final year project.

Leave a Comment