Staty: View’s State Switching within MVVM Architecture

Architecture

Let’s begin with State protocol. State must be able to represent itself on the target as well as dispose itself. In addition, we will provide any State with a delegate, I will explain it next.

Example

In this part I provide simple example of how to use this approach.

Staty Example

Advantages

  • It’s reusable as you create one specific state strategy and use it anywhere you need it just by accepting a number of protocols
  • You don’t have to worry about any other state logic and inconsistency when transitioning between states anymore: a state notifies when it exits and other state is being handled sequentaly
  • It’s extendable: when you want to add different error showing logic (for example), just create corresponding strategy and provide it through provider protocol.

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store