Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8884067
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T20:58:29+00:00 2026-06-14T20:58:29+00:00

I am not very experienced with OOP so I wanted to share what I

  • 0

I am not very experienced with OOP so I wanted to share what I am currently doing and ask for some advice about how I should go about a couple of things.

I am currently working on a simple game that uses a 2d grid. Here is a quick overview of my class structure:

  • ‘GameBoard’- has an array of the possible cell states for the game, and methods that implement the rules.
  • ‘GameView’ – has the superclass NSView, and is placed in my window as a custom view. This class is intended to read from the game board and draw the contents of the array by mapping the stares to an enumeration of images in its drawRect: method.
  • ‘GameController’ – this is an intermediate class intended to initialise the game board and view, and handle the various UI controls. This class has instance variables of the ‘GameBoard’ and ‘GameView’ type.

Originally, I was doing nearly everything in the View class, and had it working fine but it started to get hard really to follow, which was my main reason for wanting to spread my code over a new class.

I have created a method in ‘GameController’ that initialises a new game, with some user defined parameters (removed in the snippet to save space).

-(IBACTION)initialiseGame:(id)sender {
    gameBoard = [[GameBoard alloc] init...];
    gameView = [[GameView alloc] init...];
}

What I want to do here is pass the game view a pointer to the game board instance so that I can read it’s array to draw the current state of the game, something like:

-(void)initWithGameBoard:(GameBoard*)gameBoard;

Is this the right way of going about that, or should I be doing this in a different way?

My next problem with moving to the controller class is that I cannot seem to find out how to do is get a pointer to the instance of GameView that I have placed on the window in IB? Would it be better to not place the view on the window in interface builder, and instead place it on the window programatically in the initialiseGame function? If so how would I go about doing that?

I guess one other question would be, should I just scrap this idea and stick to doing everything in the GameDraw class?

Thank you very much for taking your time to read this, this is probably a very simple question to any experienced object-oriented programmer, but I cannot seem to find the answers specifically anywhere.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T20:58:31+00:00Added an answer on June 14, 2026 at 8:58 pm

    There’s more than one way to do make this work, but here’s how I would do it:

    1. Instantiate the view once in IB. Don’t invoke alloc/init yourself.
    2. In your view controller, make an outlet for your view and connect it in Interface Builder. That’s how your controller will get access to it. Your view controller will need to be the file owner — probably it already is.
    3. Design the view to be reusable. Give it a -setGameBoard: method for the controller to invoke. Make sure the view can draw something blank when it doesn’t have a game board.
    4. Write -initializeGame: like this:

      -(IBAction) initialiseGame:(id) sender {
          gameBoard = [[GameBoard alloc] init...];
          [gameView setGameBoard:gameBoard];
      }
      
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm not very experienced in C#, done some small stuff with it, but it's
I'm not very experienced with lower level things such as howmany bytes a character
I am currently doing a uni assignment as a fresher so I'm not very
I did some searching around, but I'm not very experienced in PHP, so I
Currently having this really odd problem with my layout IE7. I'm not very experienced
I'm not very experienced with JavaScript, but this code was similar to what I
I'm a long time developer but not very experienced with DNS. Here's my problem:
Building a Django app on a VPS. I am not very experienced with setting
Forgive me if this is a stupid question. I am not very experienced with
I am not a very experienced C++ programmer, i get a warning when i

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.