A hierarchy of classes of graphs is proposed which includes hypercubes, acyclic cubical complexes, median graphs, almost median graphs, premedian graphs and partial cubes. Structural properties of these classes are derived and used for the characterization of these classes by expansion procedures, for a characterization of premedian graphs by metrically defined relations on the edge set of a graph and for a characterization of median graphs by forbidden subgraphs. Moreover, a convexity lemma is proved and used to derive a simple algorithm of complexity O(mn) for recognizing median graphs.