Having harped on the evils of global variables for the length of time I've been a part of PM, I now find myself in the embarassing situation of thinking I actually need a global variable.

The situation: I'm writing a program that will play the game of Othello. (This is a precursor to playing the game of Go.) I want to write this as a OO program, both because I think it's the right way to do it and because I want practice in writing as true an OO-program as I can.

The issue: The size of the board is playing a part in a huge number of calculations, spread across all the objects. (For example, the AI object wants to know the bounds of the board. The Point object wants to know if its on the edge of the board or not. And, so on.)

Discussion: Now, one thing I'm gagging on (and this may just be unfamiliarity with the process) is should every object have a pointer to the Board? I mean, should the Point know who its Board is, so to speak?

Possible OO solutions: Maybe, have the Board give the AI a list of open squares? Maybe, have the Board tell the point, when it makes it, what sides of the Board it's on? Is this the way OO works??

------
We are the carpenters and bricklayers of the Information Age.

Vote paco for President!


In reply to OO vs. global variables... by dragonchild

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.