Why O why do we wrap UI controls???


Here's the thing: You are off making a big enterprise application that a company will use for a lot of it's work. Then, the development lead comes and tells you that you should be creating custom controls which basically wrap all the normal UI controls you are using in your application. Your first thought is: !@#$%^&*(_)(*&^%$#@!". Fret not, so was mine.


There is a simple reason why we do this. Let me give you an example. You are making a web application for a company. The web app uses controls that are common to a lot of the pages (something like a calendar control). So you create a calendar control on each of the pages and you live happily ever after. The next day, the dev lead comes and tells you that he wants the right most, bottom most pixel of the calender control to be changed from color #000000 to color #000001. So what do you do? You go to each calendar control and make the small change for each and every page. Begin to see the problem? And I'm sure you have already got the solution.


Yes, that's right. You wrap the calendar control into your own custom control (probably by deriving and maybe extending the class) and place the custom control on every page that needs the calendar. This way, any change to the calendar control can be done at a single place, i.e., in your custom control class. In addition it avoids code repitition and eases maintenance! You can also add your own custom, project specific functionality to the control at a later point without much re-work.


So remember, wrapping commonly used controls for large projects is a good practice and is worth the initial effort.


Comments (2)
  1. I've been developing software for years, but the last job I had was my first experience with true

  2. haacked says:

    Before I went that far, I think a simpler approach is to use CSS.  That way changing a color is not a compile-time operation.

    Next step is to consider a decorator approach such as an ASP.NET Control Adapter (http://weblogs.asp.net/scottgu/archive/2006/05/02/444850.aspx).

    Such an approach will save you the time from having to sub-class EVERY control when you might not need that class explosion in your project.

Comments are closed.

Skip to main content