Click here to Skip to main content
15,896,201 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have to extend some properties of TextBox and ComboBox
For ex.
First Class-> extTextBox:Inherits TextBox
Properties-> //FocusBackColorChange
//Is_Numeric_Only
//Is_DropDownList



Second Class-> extComboBox:Inherits ComboBox
Properties //FocusBackColorChange
//Is_Numeric_Only

Third Class-> Common_Properties
Properties FocusBackColorChange
Is_Numeric_Only

Now Two Properties from above are common and similarly I have to extend listbox,optionbutton,checkbox and all will have two properties in common
For Ex.FocusBackColorChange
Tagged_Data_Column_Name
Tagged_Data_Table_Name.....etc 20 properties.
The Problem Is how to Inherit the "Third Class" in "First Class" and "Second Class" as Dot net does not support Multiple Inheritance and If I use Interface I have to give the implementation for All the common properties again and It will be double job

Please,suggest me any solution.

Thanks
Sukhen Dass
Posted

1 solution

I've done the same thing previously, and just bitten the bullet, used an interface, and implemented in each inherited control..

This was necessary somewhat as (for example) I implemented some new properties that deeded different implementation depending on the control.

it also allowed me to mix these controls with others that did not implement the interface - so I could check if they did before trying to access these properties, where I had a generic reference to some control (e.g. I highlighted controls that were in error using a property "IsInError" and my validation block could just test if the control implemented the interface, and set IsInerror if it did/.



If you don't need them to be properties, you could use extension methods and implement Get_Is_Numeric_Only and Set_Is_Numeric_Only

you could (depending on the scope) add each of the controls in question to a user control that implements the common properties, and exposes any others you need - but this can be over complex when different controls are involved.
 
Share this answer
 
Comments
sukhen dass 2-Feb-12 4:59am    
in my case implementation would be same from all inherited controls....thats why the problem
sukhen dass 2-Feb-12 9:59am    
Please,team members suggest me the better solution of this problem
sukhen dass 10-Feb-12 10:08am    
Is there any alternative to achieve with code reusability
sukhen dass 26-Feb-12 0:08am    
dear team members please,suggest alternate solution

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900