Book a Demo

Author Topic: RestrictedString  (Read 3607 times)

Rico

  • EA Novice
  • *
  • Posts: 3
  • Karma: +0/-0
    • View Profile
RestrictedString
« on: February 09, 2010, 11:15:58 pm »

Hi forum,

I am trying to model a restricted string that can only have certain values (like an enumeration). Any ideas how I could model this in Enterprise Architect?

Thanks a lot,
Rico

Makulik

  • EA User
  • **
  • Posts: 400
  • Karma: +0/-0
    • View Profile
Re: RestrictedString
« Reply #1 on: February 10, 2010, 02:02:29 am »
Quote
(like an enumeration)
like an enumeration? UML doesn't restrict you to use numeric values for the enumeration.
Another alternative is to specify an appropriate constraint for the affected string attribute.

HTH
Günther

Rico

  • EA Novice
  • *
  • Posts: 3
  • Karma: +0/-0
    • View Profile
Re: RestrictedString
« Reply #2 on: February 10, 2010, 02:10:17 am »
Okay maybe "like an enumeration" was confusing.

I need to define a string class that can only have certain values, e.g., "English", "German", and "French".

Any best practice for that?

Rico

Makulik

  • EA User
  • **
  • Posts: 400
  • Karma: +0/-0
    • View Profile
Re: RestrictedString
« Reply #3 on: February 10, 2010, 02:26:03 am »
Quote
Okay maybe "like an enumeration" was confusing.
No it wasn't! That is an enumeration (see also XSD type extension facets), question is only what's the best approach to model it in a certain context. If you're modelling at business rule level I would simply use an enumeration with these strings. In an implementation model it could be different: Maybe still a (C/C++) enumeration for the possible values, and elsewhere a map associating the enum values with the strings for output & parsing. But if you have an enumeration, you should do an enumeration!

HTH
Günther

Rico

  • EA Novice
  • *
  • Posts: 3
  • Karma: +0/-0
    • View Profile
Re: RestrictedString
« Reply #4 on: February 10, 2010, 08:10:57 pm »
I am modelling an implementation model and unfortunately the restricted string needs to be a class. Question is how to model the restriction of the string to certain values?

First, I thought about constraints in the actual string class. Don't know if this is the right way to go, though.

Then, I though about creating an enumeration and having the string class "instantiating" or "using" that enumeration. This seems like bad design also.

And I didn't quite understand the map association that you mentioned.

Rico

Makulik

  • EA User
  • **
  • Posts: 400
  • Karma: +0/-0
    • View Profile
Re: RestrictedString
« Reply #5 on: February 10, 2010, 10:34:21 pm »
OK, funny enough a colleague of mine is bothering with a very similar problem actually.
I pointed him to the following direction: The goal is to have s.th. that behaves like an enum, and provides certain strings to use for parsing and output. So you should have a kind of '(Type-)Descriptor' class, where the available strings for a particular enum type are defined (maybe also an association to numeric enum values, that correspond to the strings). The Descriptor class also should act as a factory for actual instances of your restricted strings, that are modelled in tight cooperation with the Descriptor (Flyweight? Not sure). Do not allow clients to change the strings of the actual value instance classes, but let only the Descriptor class initialize these from the factory method.

That's just a rough idea, how to approach the problem. My inspiring source here mainly was how Enum is currently implemented in the C# type model (remember everything in C# is an object and has a type class finally; that's similar for Java also AFAIK).

HTH
Günther

Eve

  • EA Administrator
  • EA Guru
  • *****
  • Posts: 8110
  • Karma: +119/-20
    • View Profile
Re: RestrictedString
« Reply #6 on: February 11, 2010, 08:28:45 am »
Java even allows you to use its enum class to get the appropriate string values as shown at http://javahowto.blogspot.com/2006/10/custom-string-values-for-enum.html

Geert Bellekens

  • EA Guru
  • *****
  • Posts: 13523
  • Karma: +574/-33
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
Re: RestrictedString
« Reply #7 on: February 12, 2010, 05:36:46 pm »
Rico,

What do you mean by "the restricted string needs to be a class"?
Do you want one class that can represent all valid values ("French", "English", ...)
Or do you want to create one class for each value class French, class English,...

Geert