YADTR (Yet Another DateTime Rant)

Marko Rauhamaa marko at pacujo.net
Fri Mar 28 10:34:36 EDT 2014


Roy Smith <roy at panix.com>:

> There're certainly not mutually exclusive. Mutually exclusive means if
> you have one, you can't have the other.

Correct.

The classic inheritance diamond:

   class A(B, C):
       def add_bean(self):
           ??? # how to implement

   class B(D): pass
   class C(D): pass

   class D:
       def __init__(self):
           self.beans = 0

       def add_bean(self):
           self.beans += 1

       def bean_count(self):
           return self.beans

cannot be dealt with without A addressing the common base class D. And
once it deals with it, A can be broken by reimplementing C without
inheriting it from D:

    class C:
       def __init__(self):
           self.beans = ""

       def add_bean(self):
           self.beans += "o"

       def bean_count(self):
           return len(self.beans)

thus violating encapsulation.


Marko



More information about the Python-list mailing list