lundi 10 octobre 2016

Class providing methods inherited into class providing underlying data - How is that called?

I have a class Library which defines some methods on - kind of - abstract data. This class is then inherited into a class A or B that actually defines the data. The intention is to reuse Library with different underlying data storage models.

In Python:

class Library:
    def meth1(self, ...):
      return ...
    def meth2(self, ...):
      return ...
    def compute_property1(...):
      return ...
    def compute_property2(...):
      return ...

class B(Library):
    property1 = property(lambda s: s.compute_property1()) #plain property
    property1 = property(lambda s: s.compute_property2()) #plain property

class A(Library):
    property1 = my_property_with_fancy_caching_and_compression_and_stuff(....)
    property1 = my_property_with_fancy_caching_and_compression_and_stuff(....)

Is this pattern a well-known design approach? Does it have a name? Is there a recommended name for Library?

Aucun commentaire:

Enregistrer un commentaire