Nevron .NET Vision
Framework / System Layer / Reference Integrity

In This Topic
    Reference Integrity
    In This Topic

    Reference Integrity refers to the built-in ability of Nevron objects to consistently store, update and provide references. Generally speaking there are two types of objects:

    • Reference holders - a reference holder is every object, which stores one or more references to other objects.
    • Reference providers - a reference provider is every object, which can provide a reference to itself or another object.
     Reference Holders

    The core abstraction for a reference holder is defined by the INReferenceHolder interface. A reference holder can store one or more references to other objects of certain type, which it obtains from its reference provider. 

    Unlike other frameworks, where you should manually set the references of an object (which is not only tedious, but error prone), for a reference holder it is enough to call its UpdateReferences method to update all the references it may store. This method takes only one argument - the provider, which the object must query for references to objects of certain type.

    A reference holder must always store a reference to its reference provider - in this way even if it does not immediately cache a reference to an object of certain type, it can always query the reference provider for such reference when it is needed. This feature is often called late binding and is primary used to lighten the initial object load time as well as to minimize the memory footprint. The reference provider of a reference holder can always be obtained by the GetReferenceProvider method.

    By design, passing a value of null (in VB.NET Nothing), disconnects the object from the context in which it resides (clears all of its references).

    As far as reference integrity is concerned an object field can be:

    • Reference field - the holder uses this field to store a reference to another object, which is provided to it by its reference provider. For the purpose of reference integrity such fields are marked with the NReferenceFieldAttribute attribute.
    • Non Reference field - the holder uses this field to store a reference to another object, which is managed by the holder (for example created by it), or should simply not be treated as a reference.

    The proper implementation of the UpdateReferences method, requires from the reference holder to propagate the request to all objects, which implement the INReferenceHolder interface, but are not themselved references. This can be done in two ways:

    • Manual reference update - this type of update needs more coding and requires from the programmer to be more cautious, when it adds new non reference objects, because he(she) must manually propagate the UpdateReferences request to all of them. The advantage of the manual update is that is is faster than the automatic update.
    • Automatic reference update - this type of update is implemented by simply calling the UpdateReferences static method of the NReflector class.
     Reference Providers
    The core abstraction for a reference provider is defined by the INReferenceProvider interface. Usually a reference provider can provide references to itself or other objects of certain type. Typically this interface is implemented by objects, which are referenced by other objects.
    See Also