Code Snippet


Macros for Observers

Here are two little macros too make implementing the Observer design pattern less repetitive. This is C++ File: observermacros.h #ifndef DDM_OBSERVERMACRO_H #define DDM_OBSERVERMACRO_H #define MAKE_OBSERVABLE( obscls ) \ private:\ std::listm_observers;\ public:\ void addObserver( obscls *obs ) {\ m_observers.push_back( obs );\ }\ void delObserver( obscls *obs ) {\ m_observers.remove( obs );\ } #define NOTIFY( obscls, obsmethod, argument ) \ for( std::list::const_iterator it = m_observers.begin();\ it != m_observers.end(); it++ )\

Dynamic delegation in PHP

While working on Pixelframe I devised 2 methods to dynamically delegate tasks to appropriate functions. These methods may already be known and used but these are mine and I thought it would be good to post them. These are particularly useful for handling requests where you call a certain function/script based on one parameter ( say 'action' ) and pass the rest of the parameters to the function /script. So here goes.