| I'm a bad man, and I have sinful [ooo] thoughts, but... Is-a inheritance is extremely useful for creating extensible components. "It may
be wrong, but it's much too strong." In rust, how can you make a component that is just like another component, but ever so slightly tweaked without copying the entire external API of that other component? I understand I can wrapper with has-a relationship, intercept the correct API, and then pass through the rest of the entire interface, but how can I avoid copying the entire interface of the object when I only want to tweak something tiny? With a car, I can swap out the engine with another, I just have to make sure the external interface is the same. It may be a "bad thing", but it is extremely useful for the scenario where I say, "I want a Chevy smallblock, but I want to only tweak metal alloy on the interior piston." class MyBlock(ChevySmallBlock):
def get_interior_alloy(self):
return metals.Unobtanium
Bam. I have same item; slightly tweaked. I've used this type of pattern to great effect and I find that style of inheritance manipulation invaluable in python.How can you do this with rust? I know that is-a inheritance is sinful, but show me the better way! I truly want to know it, and I've been trying to find a pattern for this. |