Guest User

Untitled

a guest
Jun 21st, 2018
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.59 KB | None | 0 0
  1. class Book
  2. {
  3. Library[] libraries;
  4.  
  5. void RemoveFromLibrary(Library lib)
  6. {
  7. libraries.remove(lib);
  8. if (IsInLibrary(lib) && lib.HasBook(this)) // prevents call-loop
  9. lib.RemoveBook(this);
  10. }
  11.  
  12. bool IsInLibrary(Library lib)
  13. {
  14. return libraries.Contain(lib);
  15. }
  16. }
  17.  
  18.  
  19. class Library
  20. {
  21. Book[] books;
  22.  
  23. void RemoveBook(Book bk)
  24. {
  25. books.remove(bk);
  26. if (HasBook(bk) && bk.IsInLibrary(this)) // prevents call-loop
  27. bk.RemoveLibrary(this);
  28. }
  29.  
  30. bool HasBook(Book bk)
  31. {
  32. return books.Contain(bk);
  33. }
  34. }
Add Comment
Please, Sign In to add comment