Предположим, есть два класса Base1
, Base2
, которые унаследованы от общего базового класса Base
.А также есть некоторая функция ff
, которая работает с Base
.
. В C ++ можно определить шаблонный класс Derived
, который будет наследоваться от Base1
или от Base2
, создавать объектывведите и передайте их ff
:
// Given
struct Base1 : Base { };
struct Base2 : Base { };
void ff(const Base& base) { }
// you can do...
template < typename BB >
struct Derived : public BB { /* implement here what is common to both Derived1 and Derived2 */ };
struct Derived1 : public Derived<Base1> { /* implement here what is specific to Derived1 but not Derived2 */ };
struct Derived2 : public Derived<Base2> { /* implement here what is specific to Derived2 but not Derived1 */ };
// ... and live your life in peace with:
Derived1 d1;
Derived2 d2;
ff(d1);
ff(d2);
Вопрос в том, как реализовать ту же архитектуру в Python3.6?