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:

use strict; use warnings; use 5.012; use Readonly; use Account; Readonly $SPACE => q{ }; #A single space my @accounts; for my $acct_info ($ACCT_FILE) { push @accounts, Account->new(split $SPACE, $acct_info); } say get_total_followers(@accounts); #etc. #etc.

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
in thread RFC on how I'm doing when it comes to writing objects? by Lady_Aleena

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.