Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

comment on

( [id://3333] : superdoc . print w/replies, xml ) Need Help??

This may be an academic example, but it's very weird to see you set the area of a circle. Personally I'd have a constructor that takes two arguments or three arguments: either a point or two coordinates (this is open for debate) and the radius of the circle. I'd have a getter for the point and the radius, as well as getters for the area (which would be computed from the radius) and such other properties. Point may be an object if necessary, but it could also be coded as an x- and y-coordinate.

I'd (if necessary) have methods such as move to change the coordinates of the midpoint and scale to change the radius.

This seems to me the way to manipulate a circle without fussing with its implementation and that is after all one of the goals of OO.

Just my 2 cents, -gjb-

Update: Apparantly I should clarify a bit. The points I'm trying to make with my casual description of a Circle class are (at least ;) the following:

  • Getters/setters don't necessarily come in pairs and
  • you can manipulate an object other than by setting some of its properties directly
The former point is illustrated by the area example, the latter by the move method which could have been done just be modifying the coordinates of the midpoint.

As a last point: I don't care whether Radius is ann object or not since I'm not going to manipulate it directly in my example anyway.


In reply to Re: The Accessor Heresy by gjb
in thread The Accessor Heresy by Roy Johnson

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



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.