Re: Why can't switch be used for objects
- From: "cody" <deutronium@xxxxxx>
- Date: Wed, 22 Jun 2005 09:39:51 +0200
"Bruce Wood" <brucewood@xxxxxxxxxx> schrieb im Newsbeitrag
news:1119418580.496132.187080@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
> I'm a little confused by your post, since I don't see any enums
> declared anywhere in it. However, if I understand the nature of your
> problem in general, then I have a question:
The Color class IS my Enum. Is it not a enum like a c# enum but it works
like an enum though there are differences.
> Why is some outside agent (some method outside the class), sifting
> through your objects in an attempt to decide which enum to return? Why
> doesn't the class itself supply you with its appropriate enum. For
> example:
>
> enum ColorEnum
> {
> Unspecified,
> Red,
> Green,
> Blue
> }
>
> Color r = new Color(255,0,0,ColorEnum.Red);
> Color g = new Color(0,255,0,ColorEnum.Green);
> Color b = new Color(0,0,255,ColorEnum.Blue);
>
> Then you just say:
>
> ColorEnum en = g.EquivalentEnum;
>
> No switch or ifs needed. As a general rule, classes should be designed
> so that the object knows a lot about itself. If you find yourself
> writing complicated tests of any kind in client code then it's a big
> hint that your class isn't beefy enough. It's also a hint at a future
> maintenance headache, because your client code contains business logic
> that "knows too much" about your objects; such code belongs within the
> class itself.
And how do you think to convert a ColorEnum to a Color object?
.
- Follow-Ups:
- Re: Why can't switch be used for objects
- From: Bruce Wood
- Re: Why can't switch be used for objects
- References:
- Why can't switch be used for objects
- From: cody
- Re: Why can't switch be used for objects
- From: Bruce Wood
- Why can't switch be used for objects
- Prev by Date: Re: newbie: Help closing window
- Next by Date: Re: What dir executing is done from
- Previous by thread: Re: Why can't switch be used for objects
- Next by thread: Re: Why can't switch be used for objects
- Index(es):
Relevant Pages
|