- About Scala
- Documentation
- Code Examples
- Software
- Scala Developers
Enumerations / Lists of available types
Wed, 2012-02-08, 23:52
Dear all,
I have an abstract animal, and three concrete type of animals: dog, cat and pig. Each instance of one of these classes correspond to an existing animal, with his weight, his size, and all this kind of stuff.
I would like in some way to list all the available types of concrete animals, and returning a list containing for each available subtype a description. I can create an enumeration, having one value corresponding to each subclass of animals. However, this force me to update my enumeration each time I add a new subclass of animal.
The classical case is for example a web application to store data about animals: first you would have to decide which kind of animal you want to add, then you get redirected to a specific page where you can fill the necessary data for that kind of animal.
Is there a better way to do this?
Thank you for your help
Best Regards
Edmondo
I have an abstract animal, and three concrete type of animals: dog, cat and pig. Each instance of one of these classes correspond to an existing animal, with his weight, his size, and all this kind of stuff.
I would like in some way to list all the available types of concrete animals, and returning a list containing for each available subtype a description. I can create an enumeration, having one value corresponding to each subclass of animals. However, this force me to update my enumeration each time I add a new subclass of animal.
The classical case is for example a web application to store data about animals: first you would have to decide which kind of animal you want to add, then you get redirected to a specific page where you can fill the necessary data for that kind of animal.
Is there a better way to do this?
Thank you for your help
Best Regards
Edmondo