Design pattern with c++ implemention