Consider this situation: I have an aquarium simulator, where I have 5 different types of fish. Different types mean different attributes (speed, color, hunger, etc.). What if I want a user of my simulator to be able to create a new type of fish and assign it its values for its attributes?
How is this implemented by the programmer? Do I need some kind of "event handling" that will add a certain bunch of lines of code to my class "Fish"? Is that even a valid thought?
(In case of need, the language is Java. And to avoid any misunderstandings and to prevent comments such as “is this uni work?”, Yes, but it is not. But I'm not looking for an answer, I'm curious about the concept.)
EDIT: Yes, I feel bad that I did not mention the interaction method: graphical interface.
So, imagine a tab called "Add New Species", in which there is a field for each attribute of the fish (type, speed, color, etc.). Thus, the user fills in the fields with the appropriate values, and when he clicks "add", the constructor is called. At least as I imagine it. :)
java types dynamic user-controls user-input
user103798
source share