Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<h2>If your problem is performance-related...</h2> <p>I assume you'd want to save on memory of all these inheritable properties (or perhaps you have a <em>lot</em> of them), otherwise this can be trivially solved with virtual properties.</p> <p>If you need sparse inheritable properties, say if you are modelling how HTML DOM properties or CSS properties propagate, you'll need to:</p> <ol> <li>Keep a pointer to the parent node (for walking upwards)</li> <li>Use a hash dictionary to store the properties inside each class (or each instance, depending on your needs), keyed by name</li> <li>If the properties don't vary by instance, use a class-static dictionary</li> <li>If the properties can be overridden instance-by-instance, add an instance dictionary on top</li> <li>When accessing a property, start finding it at the leaf, look in the instance dictionary first, then the class-static dictionary, then walk up the tree</li> </ol> <p>Of course you can add more functionalities on top of this. This is similar to how Windows Presentation Foundation solves this problem via DependencyProperty.</p> <h2>If your problem is database-related...</h2> <p>If instead your problem is to avoid reading the database to walk up the tree (i.e. loading the parents to find inherited properties), you'll need to do some sort of caching for the parent values. Or alternatively, when you load a leaf from the database, you can load all its parents and create a master merged properties dictionary in memory.</p> <p>If you want to avoid multiple database lookups to find each parent, one trick is to encode the path to each node into a text field, e.g. "1.2.1.3.4" for a leaf on the 6th level. Then, only load up nodes that have paths which are beginning substrings. You can then get the entire parents path in one SQL query.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload