Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
I want Polymorphic enums
Message
De
02/03/2006 01:07:04
 
 
À
01/03/2006 13:05:14
Information générale
Forum:
ASP.NET
Catégorie:
Code, syntaxe and commandes
Divers
Thread ID:
01100503
Message ID:
01100743
Vues:
12
I don't know why this would be necessary really. You'd need to have the appropriate enum in each sub-class anyway, what benefit do you get in having it as an abstract? This will work fine:
public class PureBreed
{
	protected int Breed;
}
public class Dog : PureBreed
{
	public Dog()
	{
		this.Breed = (int)BreedEnum.Golden;
	}

	public enum BreedEnum : int
	{
		Collie,
		Golden,
		Lab
	}
}

public class Cat : PureBreed
{
	public Cat()
	{
		this.Breed = (int)BreedEnum.Siamese;
	}
	public enum BreedEnum : int
	{
		Abyssinian,
		RussianBlue,
		Siamese
	}
}
Or did I totally miss your point?

~~Bonnie




>This is an issue that has annoyed me for a while, but after reading Bill Caton's message #1098525, I was inspired to weigh in.
>
>I want the possibility to declare abstract or virtual enums.
>
>A simple example would be a class called Purebred with an abstract enum called Breed. I would subclass Cat and Dog classes. For dog, the breed enum would countain AfghanHound, Beagle, Collie, etc. and for cat it would be Abyssinian, Birman, CornishRex, etc. For a specific instance, a property would expose the value of a specific instance.
>
>An even more practical example might be an abstract enum called color, where each subclass would implement it to define the subset of all possible colors that it was allowed to be.
>
>Referring to Perry Forman's quote,
>
>"If you are finding you need to do something like this, the design of your program is clearly all wrong. Enums are there for hard coded groups of items that will never change during runtime. If for example you want people to add groups (e.g. add a username), you should use an alternative datasource (e.g. database, file)."
>
>Does this apply to what I would like to do?
>
>I could declare an abstract int object which Cat and Dog implemented that tied to some kind of DataTable that I pulled from a DataBase that associated ints with strings, or something equally awkward, but it isn't as clean.
>
>If someone can suggest a way to accomplish the same kind of pattern, I would appreciate it.
Bonnie Berent DeWitt
NET/C# MVP since 2003

http://geek-goddess-bonnie.blogspot.com
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform