Boost logo

Boost Users :

From: Sean Shubin (sshubin_at_[hidden])
Date: 2002-05-14 09:44:57


>From the book "Refactoring"

Sometimes you can simplify a conditional expression such as this:

  class Foo {
    void foo() {
      ...
    }
  };
  ...
  x = 0;
  ...
  if(x == 0) handleNullCondition(); //conditional expression
  else x->foo();

with something like this:

  class Foo {
    void foo() {
      ...
    }
  };
  class NullFoo {
    void foo() {
       handleNullCondition();
    }
  };
  ...
  x = new NullFoo(); //instead of x = 0
  ...
  x->foo(); //conditional expression goes away
            //polymorphism handles it instead

So if I only have one check for class Foo being null, the code becomes bigger (I create a new class). But if I had many checks all over the place, it actually simplifies the code (a lot of if statements go away).
  ----- Original Message -----
  From: Andrew R. Thomas-Cramer
  To: Boost-Users_at_[hidden]
  Sent: Tuesday, May 14, 2002 7:11 AM
  Subject: Re: [Boost-Users] boost::shared_ptr and NULL

  ----- Original Message -----
  From: "Sean Shubin" <sshubin_at_[hidden]>
  To: <Boost-Users_at_[hidden]>
  Sent: Tuesday, May 14, 2002 3:25 AM
  Subject: Re: [Boost-Users] boost::shared_ptr and NULL

> As an alternative, I usually find that the "Introduce Null Object" refactoring
  results in simpler and more readable code overall. Perhaps not as concise
  though.

  I'm not familiar with that term. Could you define it and provide an example?

        Yahoo! Groups Sponsor
              ADVERTISEMENT
             
       
       

  Info: <http://www.boost.org>
  Wiki: <http://www.crystalclearsoftware.com/cgi-bin/boost_wiki/wiki.pl>
  Unsubscribe: <mailto:boost-users-unsubscribe_at_[hidden]>

  Your use of Yahoo! Groups is subject to the Yahoo! Terms of Service.

[Non-text portions of this message have been removed]


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net