I recently had a homework question where we were supposed to work with a chess board, and place a number of queens on the board.
The question was trivial in terms of difficulty, but what I wanted to ask was this:
Should I just make a boolean 2-D array and change every position that contains a queen to 1 or should I make a private class to represent a queen, that has x and y coordinates as instance variables?
This might not seem very important or pressing, but I’m using Java and it kinda gets to the core of the concept of OO programming. If we never use the modular capabilities of Java, then why use Java at all? We might as well have written the same thing in C or Python.
Which would be more appropriate in general do you think? I would appreciate it if you could restrict your answers to ones that are backed by reason, as opposed to opinions or personal preferences.
There is no single general answer to such questions. Either one can be suitable in specific situations, solving specific problems.
The fact that Java is an OO language does not mean we must define and use classes and objects for every piece of data we need to represent.
If I understand your question correctly, you are asking about an implementation detail. Object oriented programming is not so much concerned about the specific implementation details as it is concerned about encapsulating those implementation details behind a suitable interface which represents some important domain concept well. Hence clients of the class need not know nor think about its implementation details, only about the higher level abstraction represented by an interface.