Java – alternative to observable pattern?

When some state changes occur on object2, I need to perform some tasks on object1

Is there another way to use this pattern? Maybe other classes allow me to perform this behavior?

thank you.

Solution

Just add a field of type observable to object2, add observers to it, and call notifyobservers () when changes occur

This is the meaning of "in favor of composition rather than inheritance"

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>