Also known as the Observer pattern, the publisher/subscriber pattern describes a common programming practice where one entity or object defines a subscription service for a certain event, to which any other entity can subscribe to. As the event occurs, all subscribed entities would be notified and be given an opportunity to do work at that time.

For instance, a TCP/IP socket object might define such a subscription service for the event of data arrival. A file logging object might then respond to this event by writing the received data to a local file.

Seeing as this design pattern is so effective (in many instances it can provide a more elegant alternative to inheritance), it's rather surprising that no object-oriented language supports it as a language feature, although Java does have support for this pattern in its core classes library.

Log in or register to write something here or to contact authors.