tags:

views:

369

answers:

4

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?

+1  A: 

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.

womp
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"
You could have just asked that. Your question seems to be one of semantics.
womp
A: 

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
Rik
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.
Pavel Feldman
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.
Pavel Feldman
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
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.
Pavel Feldman
A: 

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.

Pavel Feldman
A: 

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.

George Mauer