views:

66

answers:

5

I'm getting started in c# development, and heard it said that all the standard controls should be 'wrapped' in a custom class, even if I don't add any extra functionality at this point. The example that cited this case was an application where someone had developed a system, and the night before deployment the customer asked for the textboxes to behave a certain way, something similar to the old mainframe system, and the developer was able to implement this functionality in 15 minutes by modifiying their control subclass, or class, or whatever it was.

Should I create custom wrappers for the standard controls this way ?

+3  A: 

I personally don't do this and I don't think I'd recommend it if you are just getting started in C# development.

I do wrap up controls at a higher level and use a Model View Presenter pattern to separate the data and the visuals allowing a change of controls without rewriting the logic.

Matt Breckon
+2  A: 

I honestly can't see that it should be worth the bother. If a situation similar to the one you describe should appear, the same thing could still be achieved with tag mapping, which basically lets you write your own wrapper, and say, "everywhere in my code, when I'm saying TextBox, I actually mean MyCustomTextBox"

David Hedlund
+1  A: 

This sounds a lot like future proofing to me, and as habit I try to avoid making a decision on what might possibly happen. Wrapping controls like that is going to make you code more complex and more difficult to maintain. With all that being said, I'm don't know the particular situation you are in, and what you describe could be a common occurrence.

There are probably better ways to go about it, possibly through the use of interfaces and different design patterns, but you really have to use what you are comfortable with and understand well. This is especially true in projects which are chaotic and with clients who are allowed to make any decision they want at any point in time. If this is what you feel is the best way to handle this situation and you think there is a good possibility of your description happening on the project, then it may not be a bad idea. It's probably not the choice I would make, but that doesn't mean it's the wrong decision.

Kevin
+2  A: 

While the developer that you talk of is being hailed as the next messiah for their stunning piece of work, they have exhibited bad project management skills, both in allowing a customer to make a change so close to release, and for actually implementing it and rolling the product out the next morning. It may have worked that time, but the next time they try it you may end up with a massive nightmare when unexpected bugs pop up on the client system.

In any case, extending the controls in this way, just in case you may need it sometime in the future, is not good practice. Only write what you need to write to satisfy the spec - extras come later when you have time to burn.

slugster
+1  A: 

heard it said that all standard controls should be 'wrapped' in a custom class

First of all, whoever said that to you ought to read my wiki question: Ways to prevent over-engineering. It was asked to specifically help people like them....

In answer to your question, my advice would be only if necessary. If you provided a scenario then I could be more specific, however, as a general consensus it's a definite no.

James