Guest User

Untitled

a guest
May 17th, 2018
177
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.51 KB | None | 0 0
  1. class DBObject {
  2. private:
  3. . . . // state
  4. public:
  5. void saveState() { . .. }
  6. void loadState() { . .. }
  7. . . .
  8. }
  9.  
  10. class StorableShape : Shape {
  11. private DBObj ect _store;
  12. alias _store this;
  13. this( ) {
  14. _store = new DBObj ect;
  15. }
  16. . . .
  17. }
  18.  
  19. unittest {
  20. auto s = new StorableShape;
  21. s. draw( ) ; // call a Shape method
  22. s. saveState() ; // call a DBObject method
  23. // gets rewritten as s._store.saveState()
  24. Shape sh = s; // normal upcast derived -> base
  25. DBObj ect db = s; // rewritten as DBObject db = s._store
  26. }
Add Comment
Please, Sign In to add comment