I have 1000 LOC that I plan to refactor into different files and functions. The goal is to be able to test the business logic independently from the visual display. Hence, I am considering an MVC pattern.

One of the challenges is that I repeatedly need access to (properties and methods of) a unique instance of an object, let us call it a session object, which stems from a closed source library. That is why I ended up with a long code in the first place, which is largely procedural/functional.

I will pursue this object in Python 2.7.

  1. How can I transition from "spaghetti code" to a decent "lasagna" with layers, without ending up with "ravioli code" that is too modular?
  2. How can I concretely work with layers (including MVC) in Python and the object+folder structure?
  3. How can I achieve modularity when I need to make multiple calls to an instance of a session object (due to its God-like nature)?
  • 1
    consider using Anti-Corruption layer to prevent that library from influencing the rest of the code
    – gnat
    Apr 5, 2016 at 16:44
  • 1
    @gnat That basically answers my question!
    – noumenal
    Apr 5, 2016 at 16:45