Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm working with ASP.NET Web User Control (WUC) and I got to this question:

I'm creating a WUC to show an object's data. This object is already loaded when I call that WUC. I'm wondering what would be better: give the WUC the full object or only the necessary attributes?

share|improve this question

migrated from Dec 14 '11 at 3:29

This question came from our site for professional and enthusiast programmers.

If the UC is responsible for displaying the entire object, and only that object (not other objects) then it should be passed an instance of it, or a base class/interface of it.

If the UC is meant to be more general, though, or only displays a couple properties, you might just expose members for those specific properties.

share|improve this answer

Pass the full object, as long as the user control should "know of" its existence (separation of concerns). If the class for the object ever changes, you will only need to modify the user control internally, not how it is invoked.

share|improve this answer

Most controls will do just fine with the object itself. If you want to shield yourself a bit, create an interface which the object inherits, then pass the object as that interface to the UC. That way, you can change replace the object later and the UC won't care, because it only knows about the pieces in the interface.

You really don't want to pass individual properties unless it's only 1 or 2. Otherwise, you end up with functions that have a large number of parameters, or long lists of object initialization lines. Pass an object or an interface - things will be much cleaner.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.