Hi everybody.

I have a class Sudoku. And puzzle stores 2D array of type Cell.

public class Sudoku implements Iterable<Cell []>
{
  private Cell [] [] puzzle;

What I want to do is to iterate through the puzzle in different class (SudokuValidator):

public class SudokuValidator
{
  private Sudoku puzzle;

how can I do this?
So I would like to get something like

puzzle[row][col]

Recommended Answers

All 2 Replies

you can access the array by either using a constructor or a method that contains the puzzle[row][col] at its class

The normal pattern with a base clas and another that depnds on it (eg model & view) goes like this:

public static void Main(..) {
 Sudoku  theGame = new Sudoku ();
 SudokuValidator v = new SudokuValidator(theGame);

...
then in the constructor for SudokuValidator you take the instance of Suduku as a parameter and keep a copy

commented: Thanks a lot! +1
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.