I'm currently working on an independent project of writing a chess game. The issue I'm currently facing is I have a method that returns an arraylist of type Move (self explanatory) which is called when determining all of the legal moves. While this works fine, I introduced a class called Castle, which extends Move (I did this because unlike a normal move, castling affects 4 squares and not just 2).
I'd like the method getMoves() to be self contained, or be able to return all of the valid moves including objects of type Move and its child Castle.
The issue is if I include a declaration which adds valid castling moves to the method getMoves (which returns an array list of type move) I can either a.) add the arraylist as a type move, in which information is lost, or b.) a type castle, which changes the return arraylist to a type of all castle and obviously breaks the method.
Is there any graceful way to accomplish this? I'm looking for ways to solve this problem without re-writing the move class while keeping the getMoves method stand alone.
class Move { private Castle castle; //castle property //getter setter below }