Skip to content

fix: SELECT TYPE dispatch logic scattered throughout business logic violates SOLID principles #140

@krystophny

Description

@krystophny

Problem

The codebase contains extensive SELECT TYPE dispatch logic scattered throughout business logic in fortplot_figure_core.f90, violating the SOLID principles, specifically:

  • Open/Closed Principle: Business logic must be modified to add new backends
  • Dependency Inversion: High-level modules directly depend on concrete backend types
  • Single Responsibility: Figure module handles both orchestration and backend-specific rendering

Evidence

Found 14 instances of backend-specific type checks across 3 modules:

  • fortplot_figure_core.f90: 8 instances
  • fortplot_legend.f90: 4 instances
  • fortplot_animation.f90: 2 instances

Examples include:

  • Direct type checking for png_context, pdf_context, ascii_context
  • Backend-specific rendering logic mixed with business logic
  • Conditional execution based on backend type

Impact

  • Adding new backends requires modifying core business logic
  • Tight coupling between high-level and low-level modules
  • Difficult to test business logic in isolation
  • Violates architecture principle: 'NO SELECT TYPE IN BUSINESS LOGIC'

Required Fix

  1. Move all backend-specific logic to backend implementations
  2. Use polymorphic interfaces to hide backend differences
  3. Configure backend behavior at initialization time
  4. Remove all SELECT TYPE from business logic modules

Affected Files

  • src/fortplot_figure_core.f90
  • src/fortplot_legend.f90
  • src/fortplot_animation.f90

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions