objective C architecture question

Posted by thekevinscott on Stack Overflow See other posts from Stack Overflow or by thekevinscott
Published on 2010-06-06T16:24:45Z Indexed on 2010/06/06 16:32 UTC
Read the original article Hit count: 358

Filed under:
|
|

Hey folks,

I'm currently teaching myself objective C. I've gone through the tutorials, but I find I learn best when slogging through a project of my own, so I've embarked on making a backgammon app.

Now that I'm partway in, I'm realizing there's some overall architecture things I just don't understand.

I've established a "player" class, a "piece" class, and a "board" class. A piece theoretically belongs to both a player and the board. For instance, a player has a color, and every turn makes a move; so the player owns his pieces. At the same time, when moving a piece, it has to check whether it's a valid move, whether there are pieces on the board, etc.

From my reading it seems like it's frowned upon to reach across classes. For instance, when a player makes a move, where should the function live that moves the piece? Should it exist on board? This would be my instinct, as the board should decide whether a move is valid or not; but the piece needs to initialize that query, as its the one being moved, no?

Any info to help a noob would be super appreciated. Thanks guys!

© Stack Overflow or respective owner

Related posts about objective-c

Related posts about oop