Clear questions and runnable code get the best and fastest answer |
|
PerlMonks |
comment on |
( [id://3333]=superdoc: print w/replies, xml ) | Need Help?? |
Another bad sign is that you called your class 'Objects' (albeit in the directory Twitter). First of all, class names are singular, e.g. Dog, Cat, DBConnection, etc. If you need to create many objects of your class, then you can store them in an array, perhaps named @dogs, @cats, or @db_connections. Or maybe you want to store your objects in a custom container created from one of your classes named MySpecialContainer--again a singular class name. Of course, you could quickly change your class name to the singular Object, but then the problem is: you would never name a class Object--because it's non descriptive; it's like naming a variable in your program $var. When there is no obvious name for your class like Dog, Cat, or DBConnection, that might be an indication that you don't need a class at all. If all you want to do is create a bunch of useful functions, then put them in a module called Twitter::MyTwitterFunctions, and forget about classes. If you do want to stay the course with classes, your code does lend itself to creating a class named Account (or Twitter::Account). Start by defining a new() method that takes arguments such as the account name, password, etc., then think of things you would like to do with an account: tweet() a message? get_total_followers(), etc.? Then write a program that creates an Account object for each of your accounts (maybe reading each account name, password, etc. from a text file), then loop through the Account objects to get the information from each Account object and calculate the totals you want.
You can certainly spin off the work that needs to be done to subroutines, so your final program might look something like this:
You could take things a step further and create an AccountsManager class. Its new() method could take an array of Account objects as an argument, and the methods you define in the AccountsManager class could return totals for all the Account objects. You could also define add() and remove() methods for the class to allow you to change which accounts are being managed. In reply to Re: RFC on how I'm doing when it comes to writing objects?
by 7stud
|
|