
var EntityType = function(typeName, propertyNamesAndTypes) {
    this.typeName = typeName;
    this.propertyNamesAndTypes = propertyNamesAndTypes;
    this.getPropertyTypesAndNames = function() {
        return this.propertyNamesAndTypes;
    };
    this.getPropertyType = function(propertyName) {
        return this.propertyNamesAndTypes[propertyName];
    };
    this.getTypeName = function() {
        return this.typeName;
    };
    var that = this;
    for (propertyTypesAndName in propertyNamesAndTypes) {
        that[propertyTypesAndName] = function(name) {
            return function() {
                return propertyNamesAndTypes[name];
            };
        }(propertyTypesAndName);
    }
};



var Entity = function(entityType, properties) {
    this.entityType = entityType;
    this.properties = properties;
    this.getEntityType = function() {
        return this.entityType;
    };
    var that = this;
    for (propertyTypesAndName in entityType.getPropertyTypesAndNames()) {
        that[propertyTypesAndName] = function(name) {
            return function() {
                if (arguments.length == 0) {
                    return that.properties[name];
                } else {
                    var oldValue = that.properties[name];
                    that.properties[name] = arguments[0];
                    return oldValue;
                }
            };
        }(propertyTypesAndName);
    }
};





var vehicleType = new EntityType('Vehicle', {
    'maker' : 'String',              // name -> typeName
    'model' : 'String',
    'yearCreated' : 'Date',
    'speed' : 'Number',
    'miles' : 'Number'
});

var vehicle = new Entity(vehicleType, {
    'maker' : 'Toyota',
    'model' : 'Highlander',
    'yearCreated' : new Date(2003, 0, 1),
    'speed' : 120,
    'miles' : 3000
});

vehicle.drive = function() {
    }.bind(vehicle);

vehicle.stop = function() {
    }.bind(vehicle);

vehicle.performMaintenance = function() {
    }.bind(vehicle);


