locked
Question on good practice in user control design RRS feed

  • Question

  • User2106226946 posted

    User Controls are useful because you can encapsulate the logic inside it and reuse the control more times in the web application.

    I want to know if it is a good practice to increase the logic of a user control for using it more times in the web application or if it is better to duplicate the user control and change the logic in the new control to mantain the code esier to understand for the developer.

     

    So is it better to reuse the control more times and to have more logic complexity or is it better to duplicate the user control more times and having easier logic to understand?

     

    Thanks.

    Simone

    Thursday, February 23, 2012 12:00 PM

Answers

  • User455156504 posted

    Hi Simone,

    it depends on your requirements. If you want to have a generic control it could become complex, but it will fit into more scenarios. If you want to have a control which is only created for one purpose (in a sense of reusability) you should keep it simple (it only should do for what it is created and the rest should be handled anywhere else).

    For the simple scenario: You can create a base control from which other controls (depending on their purpose) can inherit and add additionally complexety. That should be the best way if you follow an OOP design, reusability, and understanding.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, February 23, 2012 1:21 PM

All replies

  • User1480927888 posted

    well there are two purpose of a user control:

    1.) create a complex control which cannot be created using out of the box server controls.

    2.) Reusability

    The logic inside can be complex but should be dependent in any sense.

    Thanks,

    Abhi

    Thursday, February 23, 2012 12:38 PM
  • User455156504 posted

    Hi Simone,

    it depends on your requirements. If you want to have a generic control it could become complex, but it will fit into more scenarios. If you want to have a control which is only created for one purpose (in a sense of reusability) you should keep it simple (it only should do for what it is created and the rest should be handled anywhere else).

    For the simple scenario: You can create a base control from which other controls (depending on their purpose) can inherit and add additionally complexety. That should be the best way if you follow an OOP design, reusability, and understanding.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, February 23, 2012 1:21 PM