Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

comment on

( #3333=superdoc: print w/replies, xml ) Need Help??
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":



  • 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 or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others rifling through the Monastery: (3)
As of 2022-01-27 06:45 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    In 2022, my preferred method to securely store passwords is:












    Results (70 votes). Check out past polls.

    Notices?