PDA

View Full Version : [ADDED] [V0.8.0] Make abstract classes like ComboBoxBase easier to inherit from



mindcore1
Jan 27, 2009, 1:11 AM
While working on creating some Extensions for the Coolite Framework, I found a large limitation with some abstract classes. A really good example of this limitation is with the ComboBoxBase class. If I wish to create a new ComboBox style control that inherits ComboBoxBase, the Items property is locked into a collection of ListItems (text and value). Here is an example of the control I am working on and I have it working, but I couldn't reuse any existing code.



<ext:IconCombo
ID="IconComboTest"
TriggerAction="All"
Mode="Local"
Editable="false"
ForceSelection="true"
Select&#111;nfocus="true"
EmptyText="Select a country"
runat="server">
<Items>
<ext:IconListItem Text="United States" Icon="FlagUs" Value="US" />
<ext:IconListItem Text="Canada" Icon="FlagCa" Value="CA" />
<ext:IconListItem Text="Russia" Icon="FlagRu" Value="RU" />
<ext:IconListItem Text="Germany" Icon="FlagDe" Value="DE" />
<ext:IconListItem Text="Italy" Icon="FlagIt" Value="IT" />
</Items>
</ext:IconCombo>


I would assume that a developer would start by creating a class similar to this:



public class IconCombo : ComboBoxBase
{

...

private IconListItemCollection items;

public IconListItemCollection Items // <= will error because the abstract class locks the type
{
get { return items; }
set { items = value; }
}

}


I would like to recommend that this collection use generics to identifythe contents collection. The complicated part of this implementationwould be the JsonConverter. To make it developer friendly, there wouldhave to be some way to convert the object, probably using JsonPropertyattributes. Anyhow, the new code would look something like this.



public class IconCombo : ComboBoxBase<IconListItem>
{

...

private ListItemCollection<IconListItem> items;

public ListItemCollection<IconListItem> Items
{
get { return items; }
set { items = value; }
}
}

public class ComboBox : ComboBoxBase<ListItem>
{

...

private ListItemCollection<ListItem> items;

public ListItemCollection<ListItem> Items
{
get { return items; }
set { items = value; }
}
}



Thanks,
MC

geoffrey.mcgill
Feb 24, 2009, 7:13 AM
Hi MC,

The ListItemCollection has been modified and committed to svn. 


Publicly available with v0.8.0.


Hope this helps.