I will describe a simple way that OO could be implemented via code inspection. In this implementation, there would be objects (but no classes), each of which contains the template for the object. There is also an "object" contract, from which all objects inherit.
I assume the following:
That I can read another contract's code.
That the blank opcodes Virtual_(Start/End) and If_Child_Wanting_(Start/End) exist. These opcodes do nothing except annotate the code for processing by another contract.
The Virtual_(Start/End) opcodes indicates that the contained code can be replaced in a child contract.
The If_Child_Wanting_(Start/End) opcodes indicate that the included code should not be executed, but might be included in a child contract. In addition, there would need to be new blank opcodes to handle a template language for use inside the If Child Wanting blocks.
The following pseudo-Serpent code would implement the object contract.
// this allows objects to have constructors
// this allows an object to have a minimum tx.value for calling it
if tx.value < $1$: // $1$ is the symbol for template variable 1
// this allows an object to only execute when a particular sender calls it
// though perhaps you would want a list, not just a single address
if tx.sender != $2$:
if msg.datasize > 0:
// a child object would implement methods here
Now consider an object for a stack
if tx.value < 100*block.basefee:
if msg.datasize > 0
if msg.data == "push": // a final method
// code for push method
if msg.data == "pop": // a virtual method
// code for pop method
// added to allow the object type to be inherited with new methods implemented
Now, assuming that I can read in 2 different contracts code, I can write a contract that implements isOfDerivedType(possible_parent, possible_child) that would tell me that the stack is derived from the object
The template language could obviously use some work. For instance, it would be nice to allow a child contract to increase the gas requirement but not decrease it.
I'm wondering what the core team thinks about code inspection of another contract and allowing blank opcodes to be used for a template language. I can think of no way to implement contract inheritance without both.