Skip to content

Latest commit

 

History

History
33 lines (23 loc) · 1.27 KB

README.md

File metadata and controls

33 lines (23 loc) · 1.27 KB

cobserver

Simple implementation of the obeserver pattern in C

Observer pattern

The observer pattern is the pattern used in the reactive programming concept.

You have one publisher and several subscribers (like with a magazine). Each time a magazine has a new issue, the subscribers receive it. The same conccept applies to the observer pattern. Each time you call the publish" method of the publisher, each of the subscribers get the info passed in to the publisher.

Where to use it

This is useful in many places. It is used in actions in gui frameworks sometimes. Let's think at another example.

You could have a sistem that reads or receives some data and you want it analysed. But in the same time you want a graph of the data and also a log of the times the data has arrived. You could have three subscribers:

  • one will analyse the data
  • one will generate and show the graph
  • one will generate a log

If later you also want to generate an spredsheet or transform the data in something else, you could just create another subscriber and subscribe it to the same publisher.

What can I find here

You have a simple implementation of the pattern in the C programming language. In the main.c file you have a very simple example that shows you how to use it.