I am seeking confirmation of what seems to be a fairly straight-forward OOP practice (for others anyway).

Let's use a common example:

A certain application deals with a central "user" ... (this "user" is the subject of its own class). This user can register itself with the system, authenticate itself (create a session), logout (destroy its session), alter its profile information, conduct searches on other "users", etc.

Is it cleaner in practice to create a "User" class that has all of the abilities above OR a "User" and an "Authentication" class that divides the abilities above accordingly? The "Authentication" class would, of course, handle authentication of the user, session management, registration, etc. The "User" class would handle the altering of profile information, searches, etc. I am consistantly hung up on the division of labor (so to speak) between classes. I run into the same question when dealing with a "Display" class ... should the "Display" class display the forms needed to authenticate or leave that to the class that handles the processing logic? (My guess is the former rather than later).

There is a distinct possibility that I am not envisioning the structure and responsibilities correctly when it comes to OOP. I have been a procedural programer for a little too long.

As always, thank you all ahead of time for your advice and guidance.

author => jeyroz


In reply to The division of (class) labor in OOP by jeyroz

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.