472,344 Members | 2,443 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,344 software developers and data experts.

Working with ENUM

I'm working with C# and I'm setting up some ENUM's I have a data and
Business layer. I'm declaring a common enum for the Data Layer. The UI
layer references the Bus layer and the bus layer references the Data layer,
but I would like to have the enum exposed to all three. Is there a way to
trickle down that enum (Like class inheritance exposes classes) so that it
can be accessed from the Business layer and UI layers? My UI layer doesn't
talk to the data layer directly and I would like to avoid having to set up
the exact same enum in more than one of the layers.

I hope this is making sense. Let me know if I need to explain some more.

Thanks in advance,
Andrea
Nov 18 '05 #1
5 2549
Andrea,

Not sure if this was really the place to have posted this question, but
assuming it isn't a crosspost then just this once I'm sure the moderator
will take a leniant view :-)

Anyways there are obviously a number of ways of doing this, but one has to
ask why the UI layer needs an enum that is declared and I assume used in the
data layer, and the business layer from your question?

I assume that the UI is providing a means for the client to manipulate data
within an instance of a class? So once it is changed, the data becomes
'dirty', is it this change you are trying to 'flag' by exposing a StatusFlag
property as an ENUM?

I am working on something at the moment and I have an ObjectStatus enum
which is simply in it's own dll and I am referencing that from my ASP.NET UI
layer, my domain model (business layer), and my repositories (data layers).
If a value has changed then I simply mark the object 'dirty' by setting the
status flag to ObjectStatus.osDirty.

ObjectStatus is just declared as a public enum within the separate DLL.

Once I finish reading Domain Driven Design by Eric Evans I may well change
my mind.

HTH
Colin B
"Andrea Williams" <an*******@hotmail.IHATESpam.com> wrote in message
news:e8***************@TK2MSFTNGP12.phx.gbl...
I'm working with C# and I'm setting up some ENUM's I have a data and
Business layer. I'm declaring a common enum for the Data Layer. The UI
layer references the Bus layer and the bus layer references the Data layer, but I would like to have the enum exposed to all three. Is there a way to
trickle down that enum (Like class inheritance exposes classes) so that it
can be accessed from the Business layer and UI layers? My UI layer doesn't talk to the data layer directly and I would like to avoid having to set up
the exact same enum in more than one of the layers.

I hope this is making sense. Let me know if I need to explain some more.

Thanks in advance,
Andrea

Nov 18 '05 #2
Nope, no a cross-post, and it's for an ASP.NET app.

In my UI, I have a search box that allows the user to search based on five
different fields in a user record.

namespace DAL
{
public enum SearchBy
{
FirstName,
LastName,
EmailAddress,
SchoolOrg,
Status
}
}

I want to be able to pass a variable and use this in all the layers, but
really the DataLayer is the one that handles the search. I figured that it
would be handy to have these values in an ENUM instead of passing the field
name, since it's only going to handle these particular fields. However, if
I add the same enum to every layer, then if another field is added, I would
need to update all the layers.

So I guess my question is, what is the best way to pass this ENUM and only
declare it in one place. Since the UI doesn't have access to the DAL, that
doesn't seem like the best place, but the DAL isn't referencing any of the
other layers and I don't want it to know or care about the BL or UIL. But I
do want to make this enum available throughout the app.

Any ideas?

Andrea

"Colin Basterfield" <co**************@hotmail.com> wrote in message
news:eQ**************@TK2MSFTNGP10.phx.gbl...
Andrea,

Not sure if this was really the place to have posted this question, but
assuming it isn't a crosspost then just this once I'm sure the moderator
will take a leniant view :-)

Anyways there are obviously a number of ways of doing this, but one has to
ask why the UI layer needs an enum that is declared and I assume used in the data layer, and the business layer from your question?

I assume that the UI is providing a means for the client to manipulate data within an instance of a class? So once it is changed, the data becomes
'dirty', is it this change you are trying to 'flag' by exposing a StatusFlag property as an ENUM?

I am working on something at the moment and I have an ObjectStatus enum
which is simply in it's own dll and I am referencing that from my ASP.NET UI layer, my domain model (business layer), and my repositories (data layers). If a value has changed then I simply mark the object 'dirty' by setting the status flag to ObjectStatus.osDirty.

ObjectStatus is just declared as a public enum within the separate DLL.

Once I finish reading Domain Driven Design by Eric Evans I may well change
my mind.

HTH
Colin B
"Andrea Williams" <an*******@hotmail.IHATESpam.com> wrote in message
news:e8***************@TK2MSFTNGP12.phx.gbl...
I'm working with C# and I'm setting up some ENUM's I have a data and
Business layer. I'm declaring a common enum for the Data Layer. The UI
layer references the Bus layer and the bus layer references the Data

layer,
but I would like to have the enum exposed to all three. Is there a way to trickle down that enum (Like class inheritance exposes classes) so that it can be accessed from the Business layer and UI layers? My UI layer

doesn't
talk to the data layer directly and I would like to avoid having to set up the exact same enum in more than one of the layers.

I hope this is making sense. Let me know if I need to explain some more.
Thanks in advance,
Andrea


Nov 18 '05 #3
Hi,

On one hand I can see that this is indeed a workable approach if you
introduce a separate assembly to hold the ENUM.

However, and you can ignore this if you like or are too far down the track,
but you really ought to read Patterns of Enterprise Appplication
Architecture by Martin Fowler, because within here there is another approach
which is far cleaner and flexible, IMHO anyways, and that is to introduce
the idea of a Criteria class which one can use singularly or as part of a
list of Criteria to construct the ultimate query passed to the database.

This makes use of an overall Repository pattern object, which uses both
MetaData Mapping, and the Query Object underneath, so the client can
stipulate which fields of the class are to be used by inserting them into a
criteria object which is then passed to the Repository, and then in the
Criteria class you could attach all kinds of different things like equal.

So to work it to your requirement you could have a ClientRepository and one
of it's methods could be to create a list of all the clients whose
attributes are made up of 1..n search criteria, so in your application
coordinator, you could do, and this a bit of a hack but hopefully helps you
to understand what I burbling on about:

CriteriaList critList = new CriteriaList();
if txtFirstName.Text != ""
{
Criteria fnCriteria = new Criteria()
criteria.Equals(Client.FirstName, txtFirstName.Text)
critList.Add(fnCriteria)
}
etc...

Then you could do:

ClientRepository clientRep = new ClientRepository()
ClientList clientList = clientRep.Matching(critList)

Now within the ClientRepository you would implement the Matching method, and
it would have access to some kind of Client mapper class so it could find
the actual field name of Client.FirstName, and that would be used along with
the Criteria object to create an actual query object so that you ended up
with

select * from client where first_name = @firstName

where @firstName is set to whatever txtFirstName.Text.

Assuming you use Test Driven Development, and NUnit, you would implement an
in memory client list, that you loaded from an XML file or something, and
then use NUnit to test the internals of your client repository and the rest
eliminating both the ASP.NET UI, and the database.

There are lots of holes in this text, and I am sure I have glossed over bits
of it, unfortunately so does Mr Fowler occasionally, however as he says
tehre is no turnkey solution, but one thing I have learnt is that by using
TDD, NUnit and tiny steps it evolves into something great.

FWIW
Colin

"Andrea Williams" <an*******@hotmail.IHATESpam.com> wrote in message
news:eD**************@TK2MSFTNGP09.phx.gbl...
Nope, no a cross-post, and it's for an ASP.NET app.

In my UI, I have a search box that allows the user to search based on five
different fields in a user record.

namespace DAL
{
public enum SearchBy
{
FirstName,
LastName,
EmailAddress,
SchoolOrg,
Status
}
}

I want to be able to pass a variable and use this in all the layers, but
really the DataLayer is the one that handles the search. I figured that it would be handy to have these values in an ENUM instead of passing the field name, since it's only going to handle these particular fields. However, if I add the same enum to every layer, then if another field is added, I would need to update all the layers.

So I guess my question is, what is the best way to pass this ENUM and only
declare it in one place. Since the UI doesn't have access to the DAL, that doesn't seem like the best place, but the DAL isn't referencing any of the
other layers and I don't want it to know or care about the BL or UIL. But I do want to make this enum available throughout the app.

Any ideas?

Andrea

"Colin Basterfield" <co**************@hotmail.com> wrote in message
news:eQ**************@TK2MSFTNGP10.phx.gbl...
Andrea,

Not sure if this was really the place to have posted this question, but
assuming it isn't a crosspost then just this once I'm sure the moderator
will take a leniant view :-)

Anyways there are obviously a number of ways of doing this, but one has to
ask why the UI layer needs an enum that is declared and I assume used in the
data layer, and the business layer from your question?

I assume that the UI is providing a means for the client to manipulate

data
within an instance of a class? So once it is changed, the data becomes
'dirty', is it this change you are trying to 'flag' by exposing a

StatusFlag
property as an ENUM?

I am working on something at the moment and I have an ObjectStatus enum
which is simply in it's own dll and I am referencing that from my ASP.NET UI
layer, my domain model (business layer), and my repositories (data layers).
If a value has changed then I simply mark the object 'dirty' by setting

the
status flag to ObjectStatus.osDirty.

ObjectStatus is just declared as a public enum within the separate DLL.

Once I finish reading Domain Driven Design by Eric Evans I may well

change my mind.

HTH
Colin B
"Andrea Williams" <an*******@hotmail.IHATESpam.com> wrote in message
news:e8***************@TK2MSFTNGP12.phx.gbl...
I'm working with C# and I'm setting up some ENUM's I have a data and
Business layer. I'm declaring a common enum for the Data Layer. The UI layer references the Bus layer and the bus layer references the Data

layer,
but I would like to have the enum exposed to all three. Is there a way

to trickle down that enum (Like class inheritance exposes classes) so
that it can be accessed from the Business layer and UI layers? My UI layer doesn't
talk to the data layer directly and I would like to avoid having to
set up the exact same enum in more than one of the layers.

I hope this is making sense. Let me know if I need to explain some more.
Thanks in advance,
Andrea



Nov 18 '05 #4
I would create another assembly (i.e. Common) that all other layers
reference(DAL,BL,UI...), and put in there the common structures, constants
and enums.

Lennin
Nov 18 '05 #5
Yes that is what I was saying amongst my ramblings...

However my pair programmer always questions everything I suggest and
seemingly it is rubbing off, finally...:-)

"Lennin Arriola" <no@spam.com> wrote in message
news:ea**************@TK2MSFTNGP11.phx.gbl...
I would create another assembly (i.e. Common) that all other layers
reference(DAL,BL,UI...), and put in there the common structures, constants
and enums.

Lennin

Nov 18 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

21
by: Andreas Huber | last post by:
Hi there Spending half an hour searching through the archive I haven't found a rationale for the following behavior. using System; // note...
31
by: Michael C | last post by:
If a class inherits from another class, say Form inherits from control, then I can assign the Form to a variable of type Control without needing an...
13
by: Don | last post by:
How do I get an Enum's type using only the Enum name? e.g. Dim enumType as System.Type Dim enumName as String = "MyEnum" enumType =...
1
by: Randy | last post by:
Hi, I downloaded and tried the ENUM++ code from CUJ http://www.cuj.com/documents/s=8470/cujboost0306besser/ but can't even get it to compile...
2
by: Randy | last post by:
Hi, I downloaded and tried the ENUM++ code from CUJ http://www.cuj.com/documents/s=8470/cujboost0306besser/ but can't even get it to compile...
7
by: Rich Grise | last post by:
OK, I don't know if this is Off-Topic for the group(s), because "QT" isn't "Pure C++", and Slackware is a distro, but those guys are sharp. :-) And...
9
by: Simon | last post by:
I've got a simple and repetitive bit of code for a function in a C implementation of the card game 31s I'm working on. BTW, I am a bit of a novice...
34
by: Steven Nagy | last post by:
So I was needing some extra power from my enums and implemented the typesafe enum pattern. And it got me to thinking... why should I EVER use...
3
by: Chevron Boyde | last post by:
Hi There I have some codes that represent Sale Types i.e. A = On Account, C = Cash, D = Debtor, V = Voucher I want to create an enum or struct...
0
by: teenabhardwaj | last post by:
How would one discover a valid source for learning news, comfort, and help for engineering designs? Covering through piles of books takes a lot of...
0
by: Kemmylinns12 | last post by:
Blockchain technology has emerged as a transformative force in the business world, offering unprecedented opportunities for innovation and...
0
jalbright99669
by: jalbright99669 | last post by:
Am having a bit of a time with URL Rewrite. I need to incorporate http to https redirect with a reverse proxy. I have the URL Rewrite rules made...
0
by: antdb | last post by:
Ⅰ. Advantage of AntDB: hyper-convergence + streaming processing engine In the overall architecture, a new "hyper-convergence" concept was...
0
by: Matthew3360 | last post by:
Hi there. I have been struggling to find out how to use a variable as my location in my header redirect function. Here is my code. ...
0
by: AndyPSV | last post by:
HOW CAN I CREATE AN AI with an .executable file that would suck all files in the folder and on my computerHOW CAN I CREATE AN AI with an .executable...
0
by: Arjunsri | last post by:
I have a Redshift database that I need to use as an import data source. I have configured the DSN connection using the server, port, database, and...
0
hi
by: WisdomUfot | last post by:
It's an interesting question you've got about how Gmail hides the HTTP referrer when a link in an email is clicked. While I don't have the specific...
0
Oralloy
by: Oralloy | last post by:
Hello Folks, I am trying to hook up a CPU which I designed using SystemC to I/O pins on an FPGA. My problem (spelled failure) is with the...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.