For Programmers: Free Programming Magazines  


Home > Archive > Java Help > June 2007 > Using enum and specific values in method.









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Using enum and specific values in method.
Philippe

2007-06-08, 10:11 pm

Hi all.

I wrote a method and I want to have only 2 possibility when using arguments.
In other words, I just want to be able to use 2 type of values.



public class DataAnalyzer {

public enum Mode { YSI, HYPERPRO } //the 2 possible values

//Specify the file type
public Mode mode;

public DataAnalyzer(Mode m) {
mode = m;
}

Here's my main :

DataAnalyzer d = new DataAnalyzer(DataAnalyzer.Mode.YSI);

I want to know if this is a good way to do. I dont like the
"DataAnalyzer.Mode.YSI". Maybe there's a better solution.

Best regards,
Phil


Steve W. Jackson

2007-06-08, 10:11 pm

In article <chfai.25548$ih7.119576@weber.videotron.net>,
"Philippe" <Philippe@Massicotte.com> wrote:

> Hi all.
>
> I wrote a method and I want to have only 2 possibility when using arguments.
> In other words, I just want to be able to use 2 type of values.
>
>
>
> public class DataAnalyzer {
>
> public enum Mode { YSI, HYPERPRO } //the 2 possible values
>
> //Specify the file type
> public Mode mode;
>
> public DataAnalyzer(Mode m) {
> mode = m;
> }
>
> Here's my main :
>
> DataAnalyzer d = new DataAnalyzer(DataAnalyzer.Mode.YSI);
>
> I want to know if this is a good way to do. I dont like the
> "DataAnalyzer.Mode.YSI". Maybe there's a better solution.
>
> Best regards,
> Phil


I think it's a good idea.

If you want to use the Mode enum locally, you might want to declare it
as a "public static enum" instead. And you should *not* make the "mode"
member variable public, but private so that it's required to be provided
in the constructor.

If you really don't want the dotted notation, however, you can move the
Mode enum outside of the DataAnalyzer class -- either in the same file
or in a separate one. But IMHO it's better design, if indeed this enum
is only for use with DataAnalyzer, if it's part of the class.

= Steve =
--
Steve W. Jackson
Montgomery, Alabama
Philippe

2007-06-08, 10:11 pm

Thank for your comments.
I corrected the public for a private member.

Best regards,
Phil

"Steve W. Jackson" <stevewjackson@knology.net> a écrit dans le message de
news: stevewjackson-70BB23.11452708062007@individual.net...
> In article <chfai.25548$ih7.119576@weber.videotron.net>,
> "Philippe" <Philippe@Massicotte.com> wrote:
>
>
> I think it's a good idea.
>
> If you want to use the Mode enum locally, you might want to declare it
> as a "public static enum" instead. And you should *not* make the "mode"
> member variable public, but private so that it's required to be provided
> in the constructor.
>
> If you really don't want the dotted notation, however, you can move the
> Mode enum outside of the DataAnalyzer class -- either in the same file
> or in a separate one. But IMHO it's better design, if indeed this enum
> is only for use with DataAnalyzer, if it's part of the class.
>
> = Steve =
> --
> Steve W. Jackson
> Montgomery, Alabama



Roedy Green

2007-06-13, 4:18 am

On Fri, 08 Jun 2007 11:45:28 -0500, "Steve W. Jackson"
<stevewjackson@knology.net> wrote, quoted or indirectly quoted someone
who said :

>If you want to use the Mode enum locally, you might want to declare it
>as a "public static enum" instead. And you should *not* make the "mode"
>member variable public, but private so that it's required to be provided
>in the constructor.
>
>If you really don't want the dotted notation, however, you can move the
>Mode enum outside of the DataAnalyzer class -- either in the same file
>or in a separate one. But IMHO it's better design, if indeed this enum
>is only for use with DataAnalyzer, if it's part of the class.


You can make it a totally separate class in its own source file. Then
you import static. See http://mindprod.com/jgloss/importstatic.html
That way you can leave off the class name.
--
Roedy Green Canadian Mind Products
The Java Glossary
http://mindprod.com
Abtisam

2007-06-16, 9:28 pm

Hilary Swank and Jennifer Aniston , Lesbian Blondes On Table!
http://www.britneyraped.com/Play?vid=726648
Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com