Lecture 4.2
Armagan Amcalar
March 2nd, 2017
To accomplish a task, by manipulating certain data.
You have an initial starting point and a goal in mind. You use software to achieve that goal.
The initial starting point and the goal is
defined in terms of Data
The methods to get there are called Procedures
How do you know what to build and how to build it?
Architecture defines a deterministic way of building assets. It provides the blueprints for the implementation.
You can build a small house in an ad-hoc fashion, without much planning. But you can’t build a skyscraper without an architecture, a clear plan and a layout.
It’s all about managing the flow of data.
An innovative type of human machine interaction with new interaction paradigms like pointing, clicking, scrolling, dragging, etc.
There is the data, the procedures to manipulate them, and how they are displayed on the screen
New modes of interaction bring new challenges in designing software!
Separate different concerns with clear boundaries
The evolution starts with an architecture called MVC — model, view, controller
The UI is the new kid on the block, deal with it separately
Keep conventional software concerns of data and procedures in a group and keep UI concerns in another group. This second group is then divided in two, for a total of 3 roles:
Models — everything about data & their manipulation
Views — everything about how the data is displayed on the screen
Controllers — handling user interaction and decide on a response
The broad term that refers to data operations. The data in the software is a representation of a real world entity, hence the name model.
Has a number of misattributions: it refers to a single entity, a group of entries and to classes that operate on these. So it's often hard to understand what one refers to as a model.
Extremely innocent, has no idea whether it's running in a GUI application or not.
Classes that define the look and the layout of a screen in an application. They provide a "view", or perspective if you will, into the data, hence the name view.
Extremely aesthetic, cares only about the looks of data and not how you should keep it or manipulate it.
Classes that define user interactions. Typically, the user interacts with items on the screen, which are parts of a view. Controllers listen these events on the views and passes the intent to the model for processing. They "control" how you, as a user, manipulate the data, hence the name controller.
Some also like to refer to controllers as the glue between the views and the models, although this is not entirely correct.
View => model : observes changes in the model
Controller => model : fetches the model and determines what operations the model should do in response to user interaction
Controller => view : listens to interaction events on the view
There are tons of variations of this simple mechanism.
Can you spot points where variations can occur?
MVC has proven extremely valuable for untangling the complexities of GUI applications. How can we use it for web applications?
A web application usually consists of a backend portion and a frontend portion. The data is kept and manipulated on the backend, and the view is on the frontend. There is a clear division between these two: the frontend lives on the browser and there is no way for the view to observe the model!
Interactions are limited to a single mechanism: the url. Users can only manipulate a web application by taking different actions on the url, called requests.
It all starts with a controller, which chooses what model to operate with, then chooses an appropriate view and passes the model to the view to get the rendered output, which usually is a piece of HTML, JSON or XML. Finally the controller returns this to the browser.
The view is completely isolated! Any changes are reflected as a new request to the backend, which triggers this cycle.
What happens when you have view-specific data, an intermediate layer of representation? Who owns it?
How do you unit test the behavior of these view-specific changes?
How do you decouple views and models?
Is there a way to address previously mentioned concerns?
An alteration on the classical MVC
Redefines communication between the roles
Introduces ViewModel and removes Controller
Addresses view-specific data problem and testability of view logic
Why do you need a controller?
Can you define it declaratively?
Are interactions really independent of views?
What happens if you tighten the coupling between the controller and the view in terms of interaction handling, and loosen the coupling between the view and the application logic?
Similar to previous models!
All the previous responsibilities of a view,
Minus observing the model. Views don't know anything about models in MVVM!
Plus, instantiating a view model to delegate data responsibilities
Extremely dummy with 0 logic and state
Eliminates the need for unit testing
The new kid on the block!
Responsible for keeping all the view-logic. View-specific data, state, interactions with the model and everything the view needs
The only interface for the view!
No view or environment specific code, so highly testable
The Model-View-Controller (MVC) Its Past and Present
http://heim.ifi.uio.no/~trygver/2003/javazone-jaoo/MVC_pattern.pdf
GUI Architectures
https://martinfowler.com/eaaDev/uiArchs.html
Pro JavaScript Design Patterns (Ross Harmes & Dustin Diaz)