ScottyBlades
ScottyBlades

Reputation: 13993

How is data binding different from using an interface?

With MVVM, the ViewModel replaces the Presenter in driving the View. The differece is that the ViewModel drives the view with DataBinding, while the Presenter drives the view with an interface.

The quote is taken from this site.

I'm having trouble finding good explanations of:

  1. What is an interface?
  2. What is data Binding?
  3. How are they different?
  4. How do their differences translate to MVVM vs MVP?

Note: The ideal answer would pertain to implementations in iOS/Swift, but I'm still interested to read answers that don't.

Upvotes: 0

Views: 111

Answers (1)

David Osborne
David Osborne

Reputation: 6791

  1. What is an interface?

In this context, the interface would be an object-oriented interface that represented an abstraction of the view. The presenter communicates with the view via an interface because it promotes a loosely coupled design. This allows different, concrete view implementations to be wired-up to the presenter, most typically a fake for testing.

  1. What is data binding?

Data binding is a mechanism, usually provided by the development environment/language that automatically synchronises UI controls and code constructs such as objects or variables. It's benefit is that developers can avoid writing their own, often tedious, code to keep UI controls and in-memory objects in sync.

  1. How are they different?

An interface is a feature of an object-oriented programming language. Data binding is a feature of a development environment/language.

  1. How do their differences translate to MVVM vs MVP?

This would depend on the underlying implementation technology. I'm not familiar with iOS/Swift so cannot comment specifically there. However, I would see the key difference in how the presenter/view model communicated with the view. In MVP, I would expect to see code setting and getting UI values and responding to user actions via events. It would all be very manual, from a code perspective. In MVVM, I would expect to see less of this type of code as the interaction would be wired-up using the development environment's data binding mechanism. Often, this is a design-time process.

Upvotes: 1

Related Questions