Book a Demo

Author Topic: Value Types: Units and multiplier  (Read 2951 times)

Angel Catala

  • EA Novice
  • *
  • Posts: 11
  • Karma: +0/-0
    • View Profile
Value Types: Units and multiplier
« on: October 23, 2015, 09:38:03 pm »
When you need to define a new Value Type where the common values are usually orders of magnitude higher than the unit. Which is the better option:

1- Define the unit whatever the actual values will be
2- Define the common multipliers
3- Define independent Value Types that represent units and multipliers

For example. If you need to model hard disks. Nowadays, TB is the usual unit, but the storage unit should be bytes (or even bits). So the options would be:

1- Define a Value Type for bytes (or even for bits), and then the value properties would be assigned with huge numbers
2- Define a Value Type for TB, and then the value properties would be assigned with lower numbers
3- Define Value Types for bits, bytes, KB, MB, TB, ...

In the third case, all the Value Types would share a common Quantity Kind (namely Storage Capacity), but they would be different types with an easy translation among them.

I look forward thoughts. Thanks !!
« Last Edit: October 23, 2015, 10:54:48 pm by acatala »

qwerty

  • EA Guru
  • *****
  • Posts: 13584
  • Karma: +397/-301
  • I'm no guru at all
    • View Profile
Re: Value Types: Units and multiples
« Reply #1 on: October 23, 2015, 10:20:16 pm »
Well, the unit is (to stay with your example) always byte (which itself is a short for 8 bit) Tera, Mega etc are just multipliers for the number itself. So the reading should correctly be e.g. (2 Tera) byte.

q.

Angel Catala

  • EA Novice
  • *
  • Posts: 11
  • Karma: +0/-0
    • View Profile
Re: Value Types: Units and multipliers
« Reply #2 on: October 23, 2015, 10:53:47 pm »
Thanks qwerty !!

Your point is to choose the option 1, so Byte is defined as a Value Type and then Property Values can be declared of type Byte that would take values of 2 x 10e9, for example, for 2 TB.

I like this option. Actually it was my first option.

Perhaps this is not the best example because someone could ask "Why not bit instead of byte ?". But this is another story.

The point is to declare the unit as Value Type even though the magnitude of the common values is going to be big.
« Last Edit: October 23, 2015, 10:55:08 pm by acatala »

qwerty

  • EA Guru
  • *****
  • Posts: 13584
  • Karma: +397/-301
  • I'm no guru at all
    • View Profile
Re: Value Types: Units and multiplier
« Reply #3 on: October 23, 2015, 11:04:57 pm »
Yes. That means you will eventually declare the type to be UnitMeasure instead of Int in order to be able to parse strings like "2T" to yield 2*1024*1024*1024 in return of a integer value. Of course YMMV and one can find examples where you need other solutions. It always depends on the domain.

q.