fork download
  1. #!/usr/bin/env python3
  2.  
  3. import random
  4.  
  5. class RandomNum:
  6. def getNum(self):
  7. return random.random()
  8.  
  9. class RandomObj:
  10. def getObj(self):
  11. return {'num': random.random()}
  12.  
  13. class Adapter:
  14. def __init__(self, adaptee):
  15. self.adaptee = adaptee
  16.  
  17. def getNum(self):
  18. return self.adaptee.getObj()['num']
  19.  
  20. n = RandomNum()
  21. o = Adapter(RandomObj())
  22.  
  23. print(n.getNum())
  24. print(o.getNum())
Success #stdin #stdout 0.01s 36984KB
stdin
Standard input is empty
stdout
0.7812617898179143
0.40180321450151557