Create an Observable Wrapper

It is important to create an observable wrapper, in order to provide a mechanism for handling references and serialization/deserialization methodology for a closed type that we can't instrument as an observable. Notice, that in the case of whether in memory storage is used, the serialization and deserialization mechanism is not necessary.

When we create a new ObservableWrapper with the mentioned functionality we must implement 3 methods:

  1. GetDependencies.

  2. Serialize.

  3. Deserialize.

Those are abstract methods of the abstract class ObservableWrapper. And its implementation is dependent from the wrapped object definition. The method GetDependencies is the responsible to return all the objects that are dependencies from the wrapped object definition. For example a list, it will return all the list elements. The method Serialize is the responsible to provide an specific serialization for the object, in order to be stored. The method Deserialize is the responsible to restore the object from a specific format in which it was stored.

The method Serialize is the responsible to provide a specific serialization for the object, in order to be stored.

The method Deserialize is responsible to restore the object from a specific format in which it was stored.

Observable Wrapper Factory

The observable wrapper factory is a mechanism to provide an ObservableWrapper for types that match a pattern or meet a condition. This is useful because there will be several types that are different but similar, this can be applied in cases of Generic types, or types inheritances.

For example: Instead of registering an ObservableWrapper for each variant of the generic type, like for List, we can create an ObservableWrapperFactory.

An ObservableWrapperFactory will be considered when the given Type has not registered a specific ObservableWrapper.

After the ObservableWrapperFactory successfully provides the ObservableWrapper, it will be registered for the Type, this will avoid unnecessary lookups on the factory.

Last updated