Jump to content

  • Log In with Google      Sign In   
  • Create Account


#ActualNercury

Posted 02 March 2013 - 06:17 AM

You can do it Java way.
Create DateDispatcher with methods:

  • changeDate(newDate)
  • addListener(listener)

Make another base class for date change listener, BaseDateChangeListener, with virtual methods:

  • virtual onMonthChange(newDate)
  • virtual onYearChange(newDate)

Make DateDisplatcher contain list of listeners and inform them about month and year change when needed.

You can use this DateDispatcher in many projects, it does not depend on specific project stuff.

Then you can make project specific class that "does stuff", named ClassThatDoesStuff that derives from BaseDateChangeListener.

 

class ClassThatDoesStuff : public BaseDateChangeListener {
public:
    virtual void onMonthChange(date newDate) {
       // do project-specific stuff
    }
    virtual void onYearChange(date newDate) {
       // do project-specific stuff
    }
}

 

And add it as listener in DateDispatcher. This way you can keep your project logic separated from this small tool logic.

Edit: for date and time manipulation you can use boost::date_time.


#1Nercury

Posted 02 March 2013 - 06:13 AM

You can do it Java way.
Create DateDispatcher with methods:

  • changeDate(newDate)
  • addListener(listener)

Make another base class for date change listener, BaseDateChangeListener, with virtual methods:

  • virtual onMonthChange(newDate)
  • virtual onYearChange(newDate)

Make DateDisplatcher contain list of listeners and inform them about month and year change when needed.

You can use this DateDispatcher in many projects, it does not depend on specific project stuff.

Then you can make project specific class that "does stuff", named ClassThatDoesStuff that derives from BaseDateChangeListener.

 

class ClassThatDoesStuff : public BaseDateChangeListener {
public:
    virtual void onMonthChange(date newDate) {
       // do project-specific stuff
    }
    virtual void onYearChange(date newDate) {
       // do project-specific stuff
    }
}

 

And add it as listener in DateDispatcher. This way you can keep your project logic separated from this small tool logic.


PARTNERS