Reputation: 1142
When the class Dog
inherits from the class Animal
, we say that 'Dog is an Animal'.
When the class Dog
has a property Name
, we say that 'Dog has a Name'.
When the class Dog
has a method void Sleep()
, we say that 'Dog can Sleep'.
What do we say when a class has an enum
? In case of the following:
enum UserType {
Admin,
Guest,
Registered
}
And where is it common to put enums? Is it usual to put all enums in one big class, like it's done with extension methods?
Upvotes: 0
Views: 154
Reputation: 381
Enum is list of the constants. That being said, you as developer determine where to use it. Usually months, days of the week, access types are common enums. For instance your example about dog. The one thing came to my mind is paw as enum, when you ask dog for its paw,and you reward him. For instance in your Dog class:
public enum Paw{ RIGHTFRONT,LEFTFRONT,RIGHTRARE,LEFTRARE }
public Dog(Paw paw){
this.paw=paw;
}
public void rewardDog(){
switch(paw){
case RIGHTFRONT: giveFood();
break;
case LEFTFRONT: giveWater();
break;
};
etc.
Then in your activity:
Dog mDog=new Dog(Paw.RIGHTFRONT);
mDog.rewardDog();
In case of UserType, consider it's as some kind of restrictions toward different user type. For instance when you load icons for the users, you can define that if usertype==Admin, then on icon there will be a crown, if usertype==Registered, there will be a star overlain on the main pic. Or admin has access to edit posts, comments; but guests and registered ones don't have that access.
Upvotes: 1