Data/Metadata Model

Motivation

A Data/Metadata Model separates information in two categories:

  • data: slow, heavyweight information that represents the content
  • metadata: fast, lightweight information that describes the content

This distinction is often driven by the need for a Model object to
present lean access to information needed for browsing, and resource consuming
access to information needed for processing.

Design

The Model class implement getters for both data and metadata.

  • Data methods retrieve the information lazily, possibly in chunks.
    Caching may not be possible if the size of the information is excessive.
  • Metadata methods may or may not be lazily retrieved, and may use caching,
    especially when backed by network.

Clarity in documentation is essential to communicate the associated cost
of retrieval.

Practical Example

An image processing program may have a Movie Model object
to represent an image file on disk

  1. class Movie(Model):
  2. def __init__(self, filename):
  3. self._filename = filename
  4. self._thumbnail = _extract_thumbnail(filename)
  5. self._length = _extract_length(filename)
  6. self._name = _extract_name(filename)
  7. # Metadata
  8. def thumbnail(self):
  9. return self._thumbnail
  10. # <similar getters for the remaining metadata>
  11. # Data
  12. def contents(self):
  13. # <...>

Properties such as thumbnail, length and name represent lean
information useful for a movie browser. This information is extracted
from the file at object instantiation and kept in memory.

The contents() method, on the other hand, retrieves the movie data
directly from the disk and makes it available for additional processing
(e.g. decoding and displaying).