note 123726 added to class.splsubject
| From: | xedin dot unknown at gmail dot com | Date: | Mon, 01 Apr 2019 18:57:49 +0000 |
| Subject: | note 123726 added to class.splsubject | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-210506@lists.php.net to get a copy of this message | ||
For a few years, I've made a few attempts to understand the architecture behind the
Subject/Observer pair. Recently I tried again. I just could not imagine why someone would design
this in the way it is documented. I mean, "what were they thinking?!", I thought. The if
things outside of the Subject could tell it when to notify observers, that would completely break
encapsulation. Because only the subject can know when events occur inside of it. And therefore,
exposing
notify() would be a huge violation to many principles of good OOP design.
However, I have come up with one scenario where this would be valid. That is, if the Subject
represents a Hook, like in WordPress. For example, in an event system where events are invoked with
a name or code, a Hook could represent a named event in the system, and by calling
notify() from outside the dispatcher could notify observers. If this is the intended
scenario, then the problems are mostly with naming: the name "Subject" implies that it is
what is being observed, and the Observer pattern is different.
----
Server IP: 208.43.231.9
Probable Submitter: 185.85.3.142 (proxied: 78.133.65.36)
----
Manual Page -- http://php.net/manual/en/class.splsubject.php
Edit -- https://master.php.net/note/edit/123726
Del: integrated -- https://master.php.net/note/delete/123726/integrated
Del: useless -- https://master.php.net/note/delete/123726/useless
Del: bad code -- https://master.php.net/note/delete/123726/bad+code
Del: spam -- https://master.php.net/note/delete/123726/spam
Del: non-english -- https://master.php.net/note/delete/123726/non-english
Del: in docs -- https://master.php.net/note/delete/123726/in+docs
Del: other reasons-- https://master.php.net/note/delete/123726
Reject -- https://master.php.net/note/reject/123726
Search -- https://master.php.net/manage/user-notes.php