dcsimg
Is there a pattern to enforce an attribute value to be one of a list of values?
1 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   shai_bentin
Posted On:   Tuesday, July 29, 2003 09:10 AM


Here is a description of a situation that I'm sure is tackled somewhere.



Say i have a class with a status attribute. I wan't that the status attributes' value will only be one of a list of String values.



Is there a pattern that deals with this or is this something which I have to write my self in the object? (I have an idea of how to do this)

Re: Is there a pattern to enforce an attribute value to be one of a list of values?

Posted By:   Anonymous  
Posted On:   Wednesday, July 30, 2003 02:16 AM

Why do you want to use a String value?

Do a google search on "typesafe enum". Or, if the behaviour of your class changes based on the status attribute, take a look at the State pattern. (You can also easily refactor the enum to a State later on.)

About | Sitemap | Contact