masks and enums

D

Daniel Pitts

You might nest them if they are used by only the enclosing class. I
find though the enums tend to be popular and reused elsewhere, so I
tend to put them in a separate public or default class in their own
file.

Also too, I tend now to put more and more logic in the enums, and less
in the classes that use them. It makes sense then to give them their
own file to grow in.
I tend to do this too. If there is behavior the should be executed
based on the enum value, I add it to the enum itself, and then just
call myEnumValue.foo(); :)

Who'd have thought that enums and polymorphism could be mixed. As
well as being singletons.
 
W

Wojtek

Roedy Green wrote :
You might nest them if they are used by only the enclosing class. I
find though the enums tend to be popular and reused elsewhere, so I
tend to put them in a separate public or default class in their own
file.

Also too, I tend now to put more and more logic in the enums, and less
in the classes that use them. It makes sense then to give them their
own file to grow in.

But the main reason is I can find them more easily then they are in
their own file.

Hmmm, I prefer to put them in the class which uses them. Rarely do I
use an enum without also using the owning class' methods.

That way I do not need to get creative with class names. So rather than
having:

FooEnum.Bar.OPTION which is used in Foo

I have

Foo.Bar.OPTION

And I always put the enum at the top of the class code. With Eclipse, I
have enums coloured differently so they are easy to spot in the source
code. And getting to the enum is a CTRL-Click away.

Just had a thought. Do you import right the enum? I only import to the
owning class, then use <class>.<enum> to use it. It sort of reads like
a sentence that way, plus I can see the owning class.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Members online

No members online now.

Forum statistics

Threads
473,770
Messages
2,569,583
Members
45,074
Latest member
StanleyFra

Latest Threads

Top