Subject.cpp 496 B

1234567891011121314151617181920212223242526272829303132
  1. #include "Observer.h"
  2. #include "Subject.h"
  3. void Subject::Attach(Observer* obv) {
  4. _obvs.push_front(obv);
  5. }
  6. void Subject::Detach(Observer* obv) {
  7. if (obv != nullptr) {
  8. _obvs.remove(obv);
  9. }
  10. }
  11. void Subject::Notify() {
  12. for (auto obv : _obvs) {
  13. obv->Update(this);
  14. }
  15. }
  16. Subject::~Subject() { }
  17. Subject::Subject() {
  18. //_obvs.clear();
  19. }
  20. string ConcreteSubject::GetState() {
  21. return _st;
  22. }
  23. void ConcreteSubject::SetState(const string& st) {
  24. _st = st;
  25. }