Passing enums across boundaries

Passing enums across boundaries

am 23.01.2008 10:35:01 von Guy

VS2005

I have a solution containing (amongst others) a Business layer project and a
DataAccess layer project.

Within these two projects I have a Class DoStuff , the business layer
doStuff makes calls to the DataAccess layer DoStuff. some of these calls
involve passing an enum as a parameter.

This enum is meaningless outside these two classes. The only way I can see
to make it visible to these two classes but not any other classes is to
define it in each class and make it Private, casting it where needed. This
however is not very clean.

Anyone have another suggestion?

Guy

Re: Passing enums across boundaries

am 23.01.2008 13:09:53 von Kevin Spencer

Why does it have to be private?

--
HTH,

Kevin Spencer
Chicken Salad Surgeon
Microsoft MVP

"guy" wrote in message
news:45ED329A-8D3F-4481-AFEA-F5F9B7034E8D@microsoft.com...
> VS2005
>
> I have a solution containing (amongst others) a Business layer project and
> a
> DataAccess layer project.
>
> Within these two projects I have a Class DoStuff , the business layer
> doStuff makes calls to the DataAccess layer DoStuff. some of these calls
> involve passing an enum as a parameter.
>
> This enum is meaningless outside these two classes. The only way I can see
> to make it visible to these two classes but not any other classes is to
> define it in each class and make it Private, casting it where needed. This
> however is not very clean.
>
> Anyone have another suggestion?
>
> Guy

Re: Passing enums across boundaries

am 23.01.2008 13:49:02 von Guy

Well it could be Protected I suppose, but what I need to do is to make theis
enum visible to two and only two classes, which are in different projects.

I dont want other classes to be able to see this enum as it is similar to
another enum that has wide visibility. This could cause confusion to other
developers.

Guy

"Kevin Spencer" wrote:

> Why does it have to be private?
>
> --
> HTH,
>
> Kevin Spencer
> Chicken Salad Surgeon
> Microsoft MVP
>
> "guy" wrote in message
> news:45ED329A-8D3F-4481-AFEA-F5F9B7034E8D@microsoft.com...
> > VS2005
> >
> > I have a solution containing (amongst others) a Business layer project and
> > a
> > DataAccess layer project.
> >
> > Within these two projects I have a Class DoStuff , the business layer
> > doStuff makes calls to the DataAccess layer DoStuff. some of these calls
> > involve passing an enum as a parameter.
> >
> > This enum is meaningless outside these two classes. The only way I can see
> > to make it visible to these two classes but not any other classes is to
> > define it in each class and make it Private, casting it where needed. This
> > however is not very clean.
> >
> > Anyone have another suggestion?
> >
> > Guy
>
>
>

Re: Passing enums across boundaries

am 23.01.2008 16:02:04 von pvdg42

"guy" wrote in message
news:7FA4C4D5-92B7-497D-8270-369CB750C128@microsoft.com...
> Well it could be Protected I suppose, but what I need to do is to make
> theis
> enum visible to two and only two classes, which are in different projects.
>
> I dont want other classes to be able to see this enum as it is similar to
> another enum that has wide visibility. This could cause confusion to other
> developers.
>
> Guy
>
> "Kevin Spencer" wrote:
>
>> Why does it have to be private?
>>
>> --
>> HTH,
>>
>> Kevin Spencer
>> Chicken Salad Surgeon
>> Microsoft MVP
>>
>> "guy" wrote in message
>> news:45ED329A-8D3F-4481-AFEA-F5F9B7034E8D@microsoft.com...
>> > VS2005
>> >
>> > I have a solution containing (amongst others) a Business layer project
>> > and
>> > a
>> > DataAccess layer project.
>> >
>> > Within these two projects I have a Class DoStuff , the business layer
>> > doStuff makes calls to the DataAccess layer DoStuff. some of these
>> > calls
>> > involve passing an enum as a parameter.
>> >
>> > This enum is meaningless outside these two classes. The only way I can
>> > see
>> > to make it visible to these two classes but not any other classes is to
>> > define it in each class and make it Private, casting it where needed.
>> > This
>> > however is not very clean.
>> >
>> > Anyone have another suggestion?
>> >
>> > Guy
>>
>>
>>

Unless your two classes are somehow related via inheritance, I doubt
"Protected" will do it.

From VS docs:
The protected keyword is a member access modifier. A protected member is
accessible from within the class in which it is declared, and from within
any class derived from the class that declared this member.

A protected member of a base class is accessible in a derived class only if
the access takes place through the derived class type.

Re: Passing enums across boundaries

am 23.01.2008 16:27:02 von Guy

I know Protected will not do it!
Kevin just asked why it had to be Private

Guy

"PvdG42" wrote:

> "guy" wrote in message
> news:7FA4C4D5-92B7-497D-8270-369CB750C128@microsoft.com...
> > Well it could be Protected I suppose, but what I need to do is to make
> > theis
> > enum visible to two and only two classes, which are in different projects.
> >
> > I dont want other classes to be able to see this enum as it is similar to
> > another enum that has wide visibility. This could cause confusion to other
> > developers.
> >
> > Guy
> >
> > "Kevin Spencer" wrote:
> >
> >> Why does it have to be private?
> >>
> >> --
> >> HTH,
> >>
> >> Kevin Spencer
> >> Chicken Salad Surgeon
> >> Microsoft MVP
> >>
> >> "guy" wrote in message
> >> news:45ED329A-8D3F-4481-AFEA-F5F9B7034E8D@microsoft.com...
> >> > VS2005
> >> >
> >> > I have a solution containing (amongst others) a Business layer project
> >> > and
> >> > a
> >> > DataAccess layer project.
> >> >
> >> > Within these two projects I have a Class DoStuff , the business layer
> >> > doStuff makes calls to the DataAccess layer DoStuff. some of these
> >> > calls
> >> > involve passing an enum as a parameter.
> >> >
> >> > This enum is meaningless outside these two classes. The only way I can
> >> > see
> >> > to make it visible to these two classes but not any other classes is to
> >> > define it in each class and make it Private, casting it where needed.
> >> > This
> >> > however is not very clean.
> >> >
> >> > Anyone have another suggestion?
> >> >
> >> > Guy
> >>
> >>
> >>
>
> Unless your two classes are somehow related via inheritance, I doubt
> "Protected" will do it.
>
> From VS docs:
> The protected keyword is a member access modifier. A protected member is
> accessible from within the class in which it is declared, and from within
> any class derived from the class that declared this member.
>
> A protected member of a base class is accessible in a derived class only if
> the access takes place through the derived class type.
>
>

Re: Passing enums across boundaries

am 24.01.2008 14:11:57 von Kevin Spencer

Well, you have a couple of choices:

1. Rename the enum and make it public.
2. Don't use an enum. Use integers instead.
3. Cast to and from integers.

--
HTH,

Kevin Spencer
Chicken Salad Surgeon
Microsoft MVP

"guy" wrote in message
news:7FA4C4D5-92B7-497D-8270-369CB750C128@microsoft.com...
> Well it could be Protected I suppose, but what I need to do is to make
> theis
> enum visible to two and only two classes, which are in different projects.
>
> I dont want other classes to be able to see this enum as it is similar to
> another enum that has wide visibility. This could cause confusion to other
> developers.
>
> Guy
>
> "Kevin Spencer" wrote:
>
>> Why does it have to be private?
>>
>> --
>> HTH,
>>
>> Kevin Spencer
>> Chicken Salad Surgeon
>> Microsoft MVP
>>
>> "guy" wrote in message
>> news:45ED329A-8D3F-4481-AFEA-F5F9B7034E8D@microsoft.com...
>> > VS2005
>> >
>> > I have a solution containing (amongst others) a Business layer project
>> > and
>> > a
>> > DataAccess layer project.
>> >
>> > Within these two projects I have a Class DoStuff , the business layer
>> > doStuff makes calls to the DataAccess layer DoStuff. some of these
>> > calls
>> > involve passing an enum as a parameter.
>> >
>> > This enum is meaningless outside these two classes. The only way I can
>> > see
>> > to make it visible to these two classes but not any other classes is to
>> > define it in each class and make it Private, casting it where needed.
>> > This
>> > however is not very clean.
>> >
>> > Anyone have another suggestion?
>> >
>> > Guy
>>
>>
>>

Re: Passing enums across boundaries

am 24.01.2008 15:25:47 von Registered User

On Thu, 24 Jan 2008 08:11:57 -0500, "Kevin Spencer"
wrote:

>Well, you have a couple of choices:
>
>1. Rename the enum and make it public.
>2. Don't use an enum. Use integers instead.
>3. Cast to and from integers.

Would the visitor pattern be of use here?

regards
A.G.

Re: Passing enums across boundaries

am 25.01.2008 12:51:28 von Kevin Spencer

No.

--
HTH,

Kevin Spencer
Chicken Salad Surgeon
Microsoft MVP

"Registered User" wrote in message
news:fu7hp3t3hu76pc6vejeobd46ljhait17jh@4ax.com...
> On Thu, 24 Jan 2008 08:11:57 -0500, "Kevin Spencer"
> wrote:
>
>>Well, you have a couple of choices:
>>
>>1. Rename the enum and make it public.
>>2. Don't use an enum. Use integers instead.
>>3. Cast to and from integers.
>
> Would the visitor pattern be of use here?
>
> regards
> A.G.