architv / soccer-cli

:soccer: Football scores for hackers. :computer: A command line interface for all the football scores.
MIT License
1.09k stars 222 forks source link

Move printing functionality into it's own module #41

Closed carlosvargas closed 8 years ago

carlosvargas commented 8 years ago

Now that we are able to print the results out into multiple formats (Issue #36), we realized that we need to separate the functionality into it's own module to make things cleaner.

I was thinking about this and here are my thoughts.

Move all of the printing code into a module called writers.py that will look like:

def get_writer(output):
    if output == 'stdout':
         return Console()
    ...

class Console:
    def live_scores(...):    
    ...

class JSON:
    def live_scores(...):   
    ...

class CSV:
    def live_scores(...):   
    ...

then in main.py we can call the factory function:

import writers

def get_live_scores(writer):
    ...
    writer.live_scores(...)

def main(..., output):
    writer = writers.get_writer(output)
    ...
    if live:
         get_live_scores(writer)

What do you guys think?

ueg1990 commented 8 years ago

i like this alot...and we can create a BaseClass such that Console/JSON/CSV can all inherit from it because they will have some similar functionality and name of functions. we can just override the functions that differ in implementation and define methods that are common in all 3 in the BaseClass.