ch39元类(python)
class Extras: def extra(self, args): # Normal inheritance: too static ... class Client1(Extras): ... # Clients inherit extra methods class Client2(Extras): ... class Client3(Extras): ... X = Client1() # Make an instance X.extra() # Run the extra methods def extra(self, arg): ... class Client1: ... # Client augments: too distributed if required(): Client1.extra = extra class Client2: ... if required(): Client2.extra = extra class Client3: ... if required(): Client3.extra = extra X = Client1() X.extra() ...