The answer depends on what you want to do .
Technically you can do three things:
- Copy nothing. Any observers will not know anything about the new facility.
- Let the new object add itself to the list of things that old observers observe. Existing observers will respond to the new facility, as will the old one.
- Create new observers who are watching the new object, as the old ones made the old object. New observers will respond to changes in the new facility, like old ones made for the old facility.
Other posters are certainly right that 1) is likely to be the preferred option, if only because executing 2 or 3 in the copy constructor means that observers are always created / copied. Nothing allows you to add observers later, if necessary.
However, you can imagine cases where other options are correct. If you want the observer to respond to any instance of this class, regardless of how it is created, then 2) is correct. If your observer performs a specific task for the object and does not care about the rest of the system, then 3) there may be a way.
It is often better to think about how your system works, rather than just following the rule. If this is not your code that you are modifying, contact the owner. And if you just donβt know what you want, select 1) and add observers later.
source share