Observer Pattern In Cee Plus Plus

ObserverPattern implementation in CeePlusPlus

AndreiAlexandrescu has written two articles which discuss different ways of implementing the ObserverPattern in CeePlusPlus.

In this model all the observers inherit from an observer class and use this to connect to the subject which needs to be observed.

In the paper FunctionalToolsForObjectOrientedTasks Yannis Smaragdakis and Brian McNamara propose a different way of implementing the ObserverPattern using FunctoidsInCpp.

FunctionalPatternSystemForObjectOrientedDesign gives a framework for the same ground and is referred to by Smaragdakis and McNamara.

I want to look at the implications of the interesting paper DeprecatingTheObserverPattern where the coding is in ScalaLanguage.

I now have a version of this code which uses FunctoidsInCpp with an extra layer of the PimplIdiom to make it work with CUDA C. See ProgrammingCudaCee for explanation.

-- JohnFletcher


Simulating a chemical plant where Feed is a feed of material into a Stream. The Unit mixer has two streams going into it (using overloaded < ).

  Feed feed1(1000.);
  Feed feed2(2000.);
  Stream stream1(feed1);
  Stream stream2(feed2);
  Unit mixer;
  mixer < stream1;
  mixer < stream2;

A later call to change the mass of the feed causes a cascade of updates to all the other plant items which depend on feed1. This can be generalised to any change of parameter.


See also ObjectFunctionalImplementation

These techniques could be used to implement updates for FunctionalReactiveProgramming. In fact the way the example is put together appears to fit the definition of ReactiveProgramming on that page.

CategoryCpp CategoryObjectFunctionalPatterns CategoryFunctionalProgramming CategoryMultiparadigm

EditText of this page (last edited March 6, 2012) or FindPage with title or text search