/**
 * Base abstract class defining the workflow for opening and processing files.
 * Inspired from https://www.codecademy.com/article/understanding-polymorphism-in-python
 * 
 * @author Hyrum D. Carroll
 * @author Gemini 3.6 Flash
 * @version 1.0
 */
abstract class FileHandler {
    /**
     * Opens a file given its filename.
     * 
     * @param filename The path or name of the file.
     * @return A status string indicating the file opening result.
     */
    public abstract String open(String filename);

    /**
     * Processes file data according to its format.
     * 
     * @param data The raw or structured data payload.
     * @return Result message after processing.
     */
    public abstract String process(String data);
}

/**
 * Handles plain text file operations.
 * @author Hyrum D. Carroll
 * @author Gemini 3.6 Flash
 */
class TextFileHandler extends FileHandler {
    @Override
    public String open(String filename) {
        return "Opening text file: " + filename;
    }

    @Override
    public String process(String data) {
        return "Processing text data: " + data;
    }
}

/**
 * Handles image file operations.
 * @author Hyrum D. Carroll
 * @author Gemini 3.6 Flash
 */
class ImageFileHandler extends FileHandler {
    @Override
    public String open(String filename) {
        return "Opening image file: " + filename;
    }

    @Override
    public String process(String data) {
        return "Processing image data: " + data;
    }
}

/**
 * Driver class demonstrating file handler polymorphism.
 * @author Hyrum D. Carroll
 * @author Gemini 3.6 Flash
 */
public class FileHandlerPolymorphismExample {
    /**
     * Uses polymorphism to open and process files regardless of concrete handler type.
     * 
     * @param handler  The file handler implementation.
     * @param filename The name of the file.
     * @param data     The data contents or metadata to process.
     */
    public static void handleFile(FileHandler handler, String filename, String data) {
        System.out.println(handler.open(filename));
        System.out.println(handler.process(data));
    }

    /**
     * Main execution method.
     * 
     * @param args Command-line arguments (unused).
     */
    public static void main(String[] args) {
        FileHandler textHandler = new TextFileHandler();
        FileHandler imageHandler = new ImageFileHandler();

        handleFile(textHandler, "document.txt", "Hello World");
        System.out.println();
        handleFile(imageHandler, "photo.jpg", "Binary image payload");
    }
}