samedi 19 décembre 2020

Modeling a tree of Configurations with Object Oriented Design

What is the best OOP way to model the following?:

There is a set of objects that inherit from class Configurable, and a tree of Configurations/sub-configurations.

Conceptually, each Configuration object represents the state of all the Configurables, and configurations inherit (and can override) settings from their parents. At any given time, one of the Configurations is “active” (you’re using that configuration when you read/write to a Configurable; if a Configuration doesn’t contain a value for a needed parameter, its parent is queried, recursively).

Possibilities:

A: Store the state of the Configurables in each Configuration. Each Configuration has a map with the key: (propertyName, ownerObject) which stores the value of that property. Every time a property of a Configurable is accessed or changed, the getter/setter for the Configurable queries the active Configuration (including parent Configurations with getters, if necessary) to retrieve/set its state.

B: Store the state of each Configurable completely within that object, as a map with the key: (propertyName, configuration). Every time a property of a Configurable is accessed/changed using regular getter/setter member functions, the Configurable queries this internal map to retrieve/set its state (using the active Configuration). If needed, information about each Configuration can be generated by querying each Configurable.

C: some other way?

Things to consider: saving/restoring Configurations, deleting Configurables and Configurations.

Aucun commentaire:

Enregistrer un commentaire