Extension vs Class For ViewModel What the advantages &amp; disadvantages to each of these approaches pertaining to creating file that takes care of the view configuration to reduce a controller's file size.

Main Purposes Are:


Memory
Performance
Testing
Usability


This is the simplest, capable of working, example to demonstrate the question, but when many views are present using many methods do any of the above concerns alter when comparing the Extension &amp; ViewModel Class?

Reminder: The ViewModel Class or Extension would be placed in a separate file.

ViewModel Approach:

    class VC: UIViewController {
        lazy var viewModel: ViewModel {
            return (main: self)
        }()

        override viewDidLoad() {
            super.viewDidLoad()

            initializeUI()
        }


        func initializeUI() {
            viewModel.configureView()
        }
    }



    class ViewModel {
        private let main: UIViewController

        init(main: UIViewController) {
            self.main = main
        }

        func configureView() {
            main.view.backgroundColor = UIColor.blue
        }
    }


Extension Approach:

    class VC: UIViewController {
        lazy var viewModel: ViewModel(main: self)

        override viewDidLoad() {
            super.viewDidLoad()

            initializeUI()
        }


        func initializeUI() {
            configureView()
        }
    }

    extension VC {
        func configureView() {
            main.view.backgroundColor = UIColor.blue
        }
    }
The viewModel property on the Extension example should be removed as it is redundant:

lazy var viewModel: ViewModel(main: self)


Irrespective of this, it seems unnecessary to create a separate ViewModel class solely for the purpose of encapsulating a configureView function. On that basis, the Extension approach seems like a much more sensible and performant way of managing this kind of configuration.