G.4. What Can You Do with Objects?You've seen that you can make objects and call object methods with them. But what are object methods for? The answer depends on the class: A Net::FTP object represents a session between your computer and an FTP server. So the methods you call on a Net::FTP object are for doing whatever you'd need to do across an FTP connection. You make the session and log in:
You can use the session object to change directory on that session:
...get files from the machine at the other end of the session:
...and plenty else, ending finally with closing the connection: $session->quit( ); In short, object methods are for doing things related to (or with) whatever the object represents. For FTP sessions, it's about sending commands to the server at the other end of the connection, and that's about it—there, methods are for doing something to the world outside the object, and the objects is just something that specifies what bit of the world (well, what FTP session) to act upon. With most other classes, however, the object itself stores some kind of information, and it typically makes no sense to do things with such an object without considering the data that's in the object.
Copyright © 2002 O'Reilly & Associates. All rights reserved. |
|