Refactoring



Originally I had multiple collection types of Books, Movies and Dvds. Each of these collections had specific fields, many of which overlapped. Refactoring to a single collection type offered multiple benefits.

  • Reuse Single Storyboard
  • Single Controller vs Controller per Type
  • Extensibility
  • Remove Multiple Switch Statements
  • Allow Multiple Item Types in Collection
  • This is just a single example of how switching from multiple collection types to a single collection type made my code reusable and more extensible to adding other collection types. at first, all over the code switch statements were checking the collection type to decide a specific code path for the item type, now there is a single code path and adding a new item will not change that.

    The original code had to make multiple query calls since each collection type was stored in a separate collection. With this code adding a new item type would mean adding a new query and another case to the switch statement.


    This updated code only searches a single query since all items are stored in a single Firebase collection. A collection can now include multiple types which allows users more options when creating a new collection.