473,386 Members | 1,702 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 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 2640
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 the missing Flags attribute enum Color {
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 explicit conversion, eg Form1 f = new Form1();...
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 = ???(enumName)
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 (see following). I have also downloaded and...
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 (see following). I have also downloaded and...
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 I've crossposted to sci.electroncs.design because...
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 at C; for the past couple of years I was using...
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 standard enums? There's now a nice little code...
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 to work with the logical names like "Cash" as...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.