http://qs321.pair.com?node_id=582951


in reply to Re^3: How do I print the page header/footer from an excel spreadsheet
in thread How di I print the page header/footer from an excel spreadsheet

Not all objects work that way under the hood, though. It's bad practice to access the hash data directly. (Though it's probably not very good practice to use arcane syntax for dynamic method names either!)

Replies are listed 'Best First'.
Re^5: How do I print the page header/footer from an excel spreadsheet
by bmann (Priest) on Nov 08, 2006 at 19:21 UTC
    Not sure if you replied before the update, but why is it bad practice? I know some properties can't be set that way, but what problems do avoid by not using the hash syntax?

      It's bad practice because if you access object data from outside the object's class, you make it difficult to change how that object operates internally later. One of the goals of OOP is to present a well-defined interface to the outside world (a class's methods) so that you can refactor the inside while keeping the client code the same.

      Suppose that in a new version of your class, you change how the data is represented internally in the hash. You also change your accessor methods to deal with the new data format and you confirm that they return the same results as before with unit tests. As long as everybody was using the accessors to get the data, everything's hunky-dory. But that one guy who accessed the hash data directly will now have broken code.

        Ahhh, I see. You were speaking in general, right? - while I was speaking specifically of Win32::OLE.

        With Win32::OLE, the hash syntax is documented and seems to be the preferred method of accessing a property. The properties are defined by the app's (in this case Excel) object model, not Win32::OLE, giving a well-defined interface for automation.