views:

56

answers:

1

I have a class which 4 fields which I need to be able to set and get. I have to use setters and getters, but also instead of using regular fields, have to use an enum. This concept confuses me - considering the fields arent necessarily constants. I'll give an example

If we call the class Bear, the 4 fields may be: name, type, nickname, homeZoo. Note all the fields are of the same type.

I need to have methods setname(string) getname() etc.

On top of my confusion with enum, I also have to be able to pass the set value of one of the fields to an interface - would I have to implement the interface on bear? Or is there some way to give the value to a method in the interfeace since an enum is a public static final sort of thing.

Your help is appreciated!

A: 

This isn't an answer but I couldn't fit it in a comment. Perhaps this will help you clarify your question if nothing else.

Classes generally DO something different in your implementation than other classes. For instance, if you have a Bear class you'd expect it to do something different from a Dog class (a Dog can wag, maybe a Bear can charge).

If, however, you are just tracking Bears for a zoo and you are also tracking Lions, what you want is probably an Animals class that contains "Bear" or "Lion" as a field.

Now, in that case Bear and Lion could be enums that are stored in the Animal class to tell what kind of critter the animal is. Is this what you were intending? If so your Animal class would have a setBreed and your enum would be a Breed {Bear, Lion, ...}.

Bill K