How to apply design patterns in server-side Dart with client-side Polymer.dart?

Issue

Using Dart with Polymer.dart allows to easily implement design patterns in the style of MVC, MVP or MVVM. I suppose that in a web environment the controller part is essentially an HTTP request handler/router that calls views or models.

The question is: can you show an example on how to connect user input data from HTML + Polymer.dart up to a database back-end?

As far as I can see, the “two-way data binding” announced by Polymer.dart seems to relate only to client-side code.

My problem is understanding how the client-side Dart code that listens to HTML form inputs may interact with the server-side Dart code. Would that be a typical AJAX request that calls the controller or is there a more idiomatic two-way data binding that I’m missing in Dart?

Solution

There is no two way data-binding between client and server in Dart (Meteor is a popular JavaScript/NodeJS framework that seems to do that). The design patterns you mentioned are pure client side. Data-binding in Dart is between the view (HTML markup) and the model (Dart code) that is holding the data for the view. The controller (or presenter or view model) is responsible to react on data changes or other user actions like pressing a button, to use a ‘service’ like HTTP (AJAX) to send the data to the server or fetch new data from the server.
The server processes and stores received data and/or responds with the requested data .

These patterns primary purpose is to make client code testable.
The view (HTML) is hard to test. Using such patterns splits the view from model and controller and makes at least these two easy testable.

There is much literature out there about such design patterns. Such questions are usually to broad for StackOverflow.

Answered By – Günter Zöchbauer

Answer Checked By – Terry (FlutterFixes Volunteer)

Leave a Reply

Your email address will not be published.