0

In a passport there is a field: First Name, and that field has a value John.

I assert that it is correct to describe the relationship as follows:

Field First Name:

  1. Has a name (First Name).
  2. Has a set of valid values (e.g. defined by regex [A-Za-z. ]{1,30}
  3. Has a description (name that stands first in the person's full name)

And Passport is a set of pairs (field : field value), such that:

  • passport has a field "First Name"
  • passport has a value for field "First Name"

Point here is that it is incorrect to say:
"First Name value is John";

The correct way (conceptually/academically) is to say:
"passport has a value 'John' for field 'First Name'".

In practical terms it means (pseudo C#):

struct Passport {
    Map<Field, object> fieldValues;
}

struct Field {
    string Name;
    string Description; 
    bool IsValidValue(object value);
}

Q: Does this make sense? Any thoughts?

5
  • Passport is made up of a number of fields? Not exactly a revolutionary concept.
    – anon
    Apr 27, 2009 at 20:33
  • Why are you rehashing the Entity Attribute Value model with different words? en.wikipedia.org/wiki/Entity-Attribute-Value_model. Is there a reason for changing the terminology?
    – S.Lott
    Apr 27, 2009 at 20:34
  • Didn't know about the EAV, that answers my question. I see this system where it is a Field itself that has a value. And that doesn't make sense.
    – THX-1138
    Apr 27, 2009 at 20:43
  • "And that doesn't make sense". It does, just different sense than well-known class-based OOP. Think about system where your entities have very weak definition, like my passport may have "FirstName", and your passport may have "NumberOfChildren" and someone else's passport may have "Address". There is no one unified place where all fields are stored, like class. So you may model Passport as List<FieldAndValue> pairs; and use it like pairs[0].Name, pairs[0].Description, pairs[0].Value Still makes sense, just a different one May 6, 2009 at 18:40
  • Field having value means there are different fields for every passport. You may want it for some reasons, like you want to change "FirstName" to "1st Name" in your passport and it should not affect mine. So I would say that there is no right and wrong decision in general, there is right and wrong decision based on your goal. Soccer ball does not make sense if you want to play tennis. May 6, 2009 at 18:45

4 Answers 4

1

This is pretty subjective and entirely context sensitive, and seems like a silly thing to nitpick over.

Correct or not, if I'm discussing "passport" with a co-worker, I'd throw something at them if they corrected me every time I said "firstName is 'john'", and told me to say it as "passport's firstname field is 'john'". You'd just come across as annoying.

2
  • 1
    The point is not to correct when spoken of, the question is how shall it be modeled; i.e. "value = Passport[Field]" vs "value = Passport.Field.Value"
    – THX-1138
    Apr 27, 2009 at 20:45
  • 2
    You could have just asked that. Your question seems to be one of semantics.
    – womp
    Apr 27, 2009 at 20:54
0

Well..not really in c# see Scott Bellware's answer to my question about C# not being Object Oriented (kinda).

In C# passport is a class so it makes perfect sense to say

  1. "The Passport has a field FirstName"
  2. For a particular instance "FirstName value is John".

Here the first clause describes the class and the next one the object. In a more OO language like ruby I think saying "passport has a value 'John' for field 'First Name'" would be equivalent, you're just describing two objects - the Passport prototype, and the instance of it in the same sentence.

I'm getting pretty confused in it myself though. The question is oddly phrased since there would doubtless be much more to a passport than just its fields, for example a long-standing and persisted identity.

0

If you are going to model such thing, then you may take a look at reflection API of java or c#. It is pretty similar to what you described. Class has set of fields, field has name, type and other attributes, not value. Object is an instance of class and you can ask object for the value of specified field. Different objects of the same class have values for the same fields, so you may say they share fields. So if you are trying to model class-based OOP then you are probably right.

However this is not the only way to do OOP. There is prototype-based OOP which looks differently, as there are no classes, only objects, so objects contain field with values so there is not much difference if you say that object contain field and field has a value.

So the answer to "Does this make sense?" I think is "yes" because similar thing is in reflection and is used widely. If it is right or wrong - depends on your needs.

UPD: regarding "value = Passport[Field]" vs "value = Passport.Field.Value" I'd introduce one more passport to make it clear

firstNameField = PassportClass.Fields["FirstName"]
myName   =   myPassport[firstNameField]
yourName = yourPassport[firstNameField]

assumes that both passport have same fields, that makes sense. Having different passports with different fields may have a sense, just a different one.

-1

No. At least in OOP, it's the field's responsibility to retain the value. Although the object is responsible for ensuring that value is consistent with the other fields or the object's constraints, the actual "containing of the value is the field's job.

Using your example:

Field First Name:

  • Has a name (First Name).
  • Has a type (int, string, object)
  • Has a description (optional)
  • Has a value

And Passport is a set fields:

  • May define constraints on such a field as defined by the model, ensuring the value and the object's state as a whole is valid
4
  • 1
    I'd say that in class-based OOP field belongs to class and does not have a value. It is so when you look at reflection in c# or java - class has fields, field has type, name, etc. And you can get value of the field from object. You declare field once, in class. You have many objects with same fields but different values. In you case, fields in your passport and in my passport are different, as they retain different values, right? So when goverment decides that "First Name" should be renamed to "1st Name" - there are million objects to rename. May 6, 2009 at 18:16
  • In your case two different passports are completely different, aren't they? As they just have set of fields, that have nothing in common. In original question at least they share same fields and have different values for them. May 6, 2009 at 18:20
  • Perhaps I should have written an object has a fixed set of values. Or I might have confused objects and classes (silly me). I'll think it over..
    – Rik
    May 6, 2009 at 18:34
  • Object may have fields that retain value, but it is just not well-known class-based OOP. It's more like what we have in javascript, where there are no classes at all, only objects. May 6, 2009 at 18:48

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.