Talk About Network

Google





Programming > C - C++ Learning > Re: Total Newbi...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 43 of 53 Topic 4060 of 4400
Post > Topic >>

Re: Total Newbie Backward Compat Question

by "Daniel T." <daniel_t@[EMAIL PROTECTED] > Mar 16, 2008 at 09:37 AM

In article <J8ydneX3O515aEbanZ2dnUVZ8hednZ2d@[EMAIL PROTECTED]
>,
 Francis Glassborow <francis.glassborow@[EMAIL PROTECTED]
> wrote:

> Daniel T. wrote:
> > Francis Glassborow <francis.glassbo...@[EMAIL PROTECTED]
> wrote:
> > 
> >> This thread begins to smell of dogma.
> > 
> > Agreed, but it is the nature of the environment, we are talking
> > generalities here, not specifics.
> > 
> >> If someone advocated that setters
> >> should always/never return the prior value I would disagree.
> > 
> > Any rule has times when it should be broken, that doesn't mean it
> > shouldn't be a rule.
> > 
> >> IMHO any time that you have a situation where it is very likely that
the
> >> programmer will wish to change state tem****arily and then restore the
> >> old state is one where a getter might legitimately return the prior
state.
> > 
> > And IMHO any time that you have a situation where it is very likely
> > that a client will wish to change the state of an object tem****arily
> > and then restore the old state is one where the object might
> > legitimately provide such functionality. Something like this for
> > example:
> > 
> > class Object {
> > public:
> >    int getValue() const;
> >    int getOldValue() const;
> >    void setValue( int v );
> >       // ensure: getOldValue() == old getValue() &&
> >       //    getValue() == v
> >    void resetValue();
> >       // ensure: getValue() == getOldValue() &&
> >       //    getOldValue() == old getOldValue()
> > };
> > 
> > I guess we can just call this a style difference and agree to
> > disagree.
> 
> However that does not work if we want to stack such state changes for 
> later restoration (at least if I understand your suggestion.

Now you are changing the problem statement on me. :-) In that case it 
would be better to move that into an adaptor. The adaptor can have a 
multi-level stack based system embedded in it if the client needs such 
functionality, and those who don't need it, don't pay for it.

Something like:

class Object {
   int value;
public:
   int getValue() const { return value; }
   void setValue( int v ) { value = v; }
};

class ObjectWithUndo
{
   stack< Object > o;
public:
   int getValue() const { return o.top().getValue(); }
   void setValue( int v ) {
      o.push( o.top() );
      o.setValue( v );
   }
   void undo() {
      o.pop();
   }
};

Deriving both of the above from an ABC that has both the get and set as 
pure-virtual functions may be useful in some contexts.
 




 53 Posts in Topic:
Total Newbie Backward Compat Question
Hal Vaughan <hal@[EMAI  2008-03-10 05:38:03 
Re: Total Newbie Backward Compat Question
Richard Heathfield <rj  2008-03-10 05:48:22 
Re: Total Newbie Backward Compat Question
Hal Vaughan <hal@[EMAI  2008-03-10 05:49:42 
Re: Total Newbie Backward Compat Question
Richard Heathfield <rj  2008-03-10 06:24:13 
Re: Total Newbie Backward Compat Question
Hal Vaughan <hal@[EMAI  2008-03-11 14:35:17 
Re: Total Newbie Backward Compat Question
Crazy c <chrisNchrist@  2008-03-10 04:12:17 
Re: Total Newbie Backward Compat Question
Richard Heathfield <rj  2008-03-10 12:05:13 
Re: Total Newbie Backward Compat Question
"Daniel T." <  2008-03-11 06:37:11 
Re: Total Newbie Backward Compat Question
"Chris ( Val )"  2008-03-10 06:15:26 
Re: Total Newbie Backward Compat Question
Richard Heathfield <rj  2008-03-10 14:21:14 
Re: Total Newbie Backward Compat Question
"Chris ( Val )"  2008-03-11 02:15:39 
Re: Total Newbie Backward Compat Question
Richard Heathfield <rj  2008-03-11 10:29:42 
Re: Total Newbie Backward Compat Question
Bart van Ingen Schenau &l  2008-03-11 18:58:25 
Re: Total Newbie Backward Compat Question
"Daniel T." <  2008-03-12 06:26:50 
Re: Total Newbie Backward Compat Question
Bart van Ingen Schenau &l  2008-03-12 17:43:08 
Re: Total Newbie Backward Compat Question
"Chris ( Val )"  2008-03-11 04:21:32 
Re: Total Newbie Backward Compat Question
Richard Heathfield <rj  2008-03-11 14:56:52 
Re: Total Newbie Backward Compat Question
Anand Hariharan <mailt  2008-03-11 19:31:54 
Re: Total Newbie Backward Compat Question
"Chris ( Val )"  2008-03-12 06:15:16 
Re: Total Newbie Backward Compat Question
"Chris ( Val )"  2008-03-12 06:19:55 
Re: Total Newbie Backward Compat Question
"Chris ( Val )"  2008-03-12 06:27:42 
Re: Total Newbie Backward Compat Question
"Chris ( Val )"  2008-03-12 06:54:16 
Re: Total Newbie Backward Compat Question
Bart van Ingen Schenau &l  2008-03-12 18:40:28 
Re: Total Newbie Backward Compat Question
"Chris ( Val )"  2008-03-12 07:10:18 
Re: Total Newbie Backward Compat Question
Richard Heathfield <rj  2008-03-12 14:28:48 
Re: Total Newbie Backward Compat Question
Hal Vaughan <hal@[EMAI  2008-03-13 05:43:14 
Re: Total Newbie Backward Compat Question
Richard Heathfield <rj  2008-03-13 07:11:42 
Re: Total Newbie Backward Compat Question
Jerry Coffin <jcoffin@  2008-03-14 00:25:02 
Re: Total Newbie Backward Compat Question
Hal Vaughan <hal@[EMAI  2008-03-13 03:23:30 
Re: Total Newbie Backward Compat Question
Philip Potter <pgp@[EM  2008-03-13 15:57:05 
Re: Total Newbie Backward Compat Question
"Daniel T." <  2008-03-12 11:46:58 
Re: Total Newbie Backward Compat Question
Bart van Ingen Schenau &l  2008-03-14 21:34:35 
Re: Total Newbie Backward Compat Question
"Daniel T." <  2008-03-14 22:01:32 
Re: Total Newbie Backward Compat Question
Francis Glassborow <fr  2008-03-15 10:02:29 
Re: Total Newbie Backward Compat Question
Anand Hariharan <mailt  2008-03-12 18:36:13 
Re: Total Newbie Backward Compat Question
"Daniel T." <  2008-03-13 06:52:53 
Re: Total Newbie Backward Compat Question
Anand Hariharan <mailt  2008-03-12 23:36:10 
Re: Total Newbie Backward Compat Question
Micah Cowan <micah@[EM  2008-03-14 09:40:31 
Re: Total Newbie Backward Compat Question
"Daniel T." <  2008-03-13 10:23:19 
Re: Total Newbie Backward Compat Question
Bart van Ingen Schenau &l  2008-03-14 21:45:47 
Re: Total Newbie Backward Compat Question
"Daniel T." <  2008-03-15 07:14:33 
Re: Total Newbie Backward Compat Question
Francis Glassborow <fr  2008-03-15 16:14:23 
Re: Total Newbie Backward Compat Question
"Daniel T." <  2008-03-16 09:37:37 
Re: Total Newbie Backward Compat Question
"Chris ( Val )"  2008-03-18 05:04:15 
Re: Total Newbie Backward Compat Question
"Chris ( Val )"  2008-03-18 05:40:29 
Re: Total Newbie Backward Compat Question
Richard Heathfield <rj  2008-03-18 22:54:23 
Re: Total Newbie Backward Compat Question
"Chris ( Val )"  2008-03-18 07:12:06 
Re: Total Newbie Backward Compat Question
"Chris ( Val )"  2008-03-21 05:44:42 
Re: Total Newbie Backward Compat Question
Richard Heathfield <rj  2008-03-21 13:34:56 
Re: Total Newbie Backward Compat Question
Ben Bacarisse <ben.use  2008-03-12 18:05:26 
Re: Total Newbie Backward Compat Question
"Daniel T." <  2008-03-12 20:46:50 
Re: Total Newbie Backward Compat Question
Ben Bacarisse <ben.use  2008-03-13 01:57:08 
Re: Total Newbie Backward Compat Question
Ben Bacarisse <ben.use  2008-03-13 18:54:38 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
localhost-V2008-12-19 Wed Jan 7 12:02:39 PST 2009.