Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Copying listeners/observers in a copy constructor

Tags:

java

I'm programming a class that implements the observable pattern (not the interface) and I'm thinking about whether or not the copy constructor should also copy the listeners.

On the one hand the copy constructor should create an instance that is as close as possible to the original instance so that it can be swapped out in the display context.

On the other hand this would assume the listeners can cope with that kind of thing.

Any thoughts? Are there any best practices?

like image 371
shezi Avatar asked Jan 25 '23 00:01

shezi


1 Answers

Don't copy. The listeners are not aware of the new object and are not expecting to receive messages related to it.

like image 56
finnw Avatar answered Jan 26 '23 13:01

finnw