fusesource / jansi

Jansi is a small java library that allows you to use ANSI escape sequences to format your console output which works even on windows.
http://fusesource.github.io/jansi/
Apache License 2.0
1.11k stars 140 forks source link

refactor using delegate (class TerminalCommandProcessor) instead of inheritance #151

Closed Arnaud-Nauwynck closed 5 years ago

Arnaud-Nauwynck commented 5 years ago

introduce class TerminalCommandProcessor to extract code specific to processing ansi escape commands (currently mixed into AnsiOutputStream, and using override...) .. so change class inheritance by delegation...(Design Pattern best practices). .. so also refactor to class WindowsTerminalCommandProcessor extends TerminalCommandProcessor instead of extending both WindowsAnsiOutputStream and WindowsAnsiPrintStream

instead of

   AnsiOutputStream               AnsiPrintStream        <=== lot of Copy&Paste
          /\                              /\
       extends                        extends
           |                              |
   WindowsAnsiOutputStream        WindowsAnsiPrintStream   <=== also lot of Copy&Paste

refactor as

   AnsiOutputStream                      AnsiPrintStream     <==== still lot of Copy&Paste
                   \                         /         ( ... cf other PR to fix this )
                   uses                   uses
                      \                    /
                      1 \/               \/ 1
                        TerminalCommandProcessor     <---  factory ---  TerminalType
                                     /\
                                      |
                          WindowsAnsiPrintStream
hboutemy commented 5 years ago

good idea but too complex code rewrote it, keeping naming and package conventions, avoiding Writer, keeping compatibility with previous API