Skip to content

Need Help with R.oo and "multiple inheritance"

1 message · Ken-JP

#
This is what I'm trying to do:

HasPersistence - an Interface class which implements things like
WriteToDisk(), ReadFromDisk()
B isA A
C isA A, but also implements HasPersistence

My solution in R.oo is to have a root class called A which implements
IsPersistent() by returning FALSE, but is overrideable by C to return TRUE. 
C will also implement WriteToDisk() and ReadFromDisk().  This solution will
work, but is kludgy, because it is not directly obvious that IsPersistent(),
WriteToDisk(), and ReadFromDisk() go together in a conceptual
HasPersistence.

Is there a more R.oo-clean-way of multiply inheriting like this, so if
someone else reads my code, the concept of HasPersistence is more obvious? 
In other words, could I actually have a HasPersistence class and have C
inherit from A and implement HasPersistence also?

- Ken