Re: Why can't switch be used for objects

Tech Tip: Click here to run a free scan for Windows Errors and optimize PC performance




"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?


.



Relevant Pages

  • Re: A Question on VB Classes
    ... ' Use an enum if you want to control allowed values for Color ... Private m_Color As ColorEnum ... Public Property NameAs String ...
    (microsoft.public.dotnet.languages.vb)
  • Re: Why cant switch be used for objects
    ... doesn't the class itself supply you with its appropriate enum. ... enum ColorEnum ... hint that your class isn't beefy enough. ... because your client code contains business logic ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Why cant switch be used for objects
    ... My one and only problem is that I do *not* want to declare an extra enum ... because my class already has enum semantics and I want to use it in a way I ... > hint that your class isn't beefy enough. ... because your client code contains business logic ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: placement new and alignment
    ... After some reasoning, and before reading your hint, I came out with the ... struct TypeGCD ... value1 = offsetof(this_t, second), ...
    (microsoft.public.vc.language)
  • Re: Interface and enums
    ... I would implement the interface and fill the enum with Strawberry and ... Your client code could choose one of your jams. ... If you declare the empty interface then the only thing ...
    (microsoft.public.dotnet.languages.csharp)