patterns Flashcards
What is MVC?
MVC is an architectural design pattern that encourages improved application organization through a separation of concerns. It enforces the isolation of business data (Models) from user interfaces (Views), with a third component (Controllers) traditionally managing logic and user-input. The pattern was originally designed by Trygve Reenskaug during his time working on Smalltalk-80 (1979).
What is the importance of the MVC (model view controller) pattern to javascript?
JavaScript now has a number of frameworks boasting support for MVC (or variations on it, which we refer to as the MV* family), allowing developers to easily add structure to their applications without great effort.
These frameworks include the likes of Backbone, Ember.js and AngularJS.
What is the purpose of model in MVC patterns?
Models is the data manager for an application. They represent unique forms of data that an application may require so are neither concerned with the user-interface nor presentation layers. When a model changes (e.g when it is updated), it will typically notify its observers (e.g views, a concept we will cover shortly) that a change has occurred so that they may react accordingly.
What are views in the MVC design pattern?
Views
Views are a visual representation of models that present a filtered view of their current state. Whilst Smalltalk views are about painting and maintaining a bitmap, JavaScript views are about building and maintaining a DOM element. Java views would have been use of Graphical User Interface libraries or JavaServerPages.
list some benefits of MVC?
Easier overall maintenance. When updates need to be made to the application it is very clear whether the changes are data-centric, meaning changes to models and possibly controllers, or merely visual, meaning changes to views.
Decoupling models and views means that it is significantly more straight-forward to write unit tests for business logic
Duplication of low-level model and controller code (i.e what we may have been using instead) is eliminated across the application
Depending on the size of the application and separation of roles, this modularity allows developers responsible for core logic and developers working on the user-interfaces to work simultaneously
What are disadvantages of MVVM?
For simpler UIs, MVVM can be overkill
Whilst data-bindings can be declarative and nice to work with, they can be harder to debug than imperative code where we simply set breakpoints
Data-bindings in non-trivial applications can create a lot of book-keeping. We also don’t want to end up in a situation where bindings are heavier than the objects being bound to
In larger applications, it can be more difficult to design the ViewModel up front to get the necessary amount of generalization
What are some of the advantages of MVVM?
MVVM Facilitates easier parallel development of a UI and the building blocks that power it
Abstracts the View and thus reduces the quantity of business logic (or glue) required in the code behind it
The ViewModel can be easier to unit test than event-driven code
The ViewModel (being more Model than View) can be tested without concerns of UI automation and interaction
What is the Adapter Pattern?
The Adapter Pattern translates an interface for an object or class into an interface compatible with a specific system.
Adapters basically allow objects or classes to function together which normally couldn’t due to their incompatible interfaces. The adapter translates calls to its interface into calls to the original interface and the code required to achieve this is usually quite minimal.
One example of an adapter we may have used is the jQuery jQuery.fn.css() method
What is a facade?
The Facade Pattern provides a simpler abstracted interface to a larger (potentially more complex) body of code.
Facades can be frequently found across the jQuery library and provide developers easy access to implementations for handling DOM manipulation, animation and of particular interest, cross-browser Ajax.
What is a container pattern?
A Container is an object created to hold other objects that are accessed, placed, and maintained with the class methods of the container - queues, sets, lists, vectors, and caches all fit this description. These objects - theelementsof the container - are usually allowed to be of any class and may be of the container class itself. Every Container should also have an associated Iterator type that can be used to iterate through the elements of the container.
Explain what the ambassador container pattern means?
Ambassador/Proxy pattern
The ambassador pattern is another way to run additional services together with your main application container but it does so through a proxy. The primary goal of an ambassador container is to simplify the access of external services for the main application where the ambassador container acts as a service discovery layer
Explain the sidecar pattern in containers|?
Sidecar pattern
The sidecar container extends and works with the primary container. This pattern is best used when there is a clear difference between a primary container and any secondary tasks that need to be done for it.
For example, a web server container (a primary application) that needs to have its logs parsed and forwarded to log storage (a secondary task) may use a sidecar container that takes care of the log forwarding. This same sidecar container can also be used in other places in the stack to forward logs for other web servers or even other applications
Multi-node application patterns in containers are?
In a multi-node pattern, containers are not on a single machine or node, instead these more advanced patterns coordinate communications across multiple nodes. According to Brendan Burns, “modular containers make it easier to build coordinated multi-node distributed applications.”
Leader election container pattern.
The idea behind this pattern is that the leader election containers can be built once and reused across your application. It addresses the common problem with distributed systems that have replicated processes by having the ability to elect a leader.
Work Queue pattern
The generic work queue container in this case does the heavy lifting to coordinate the queue. This addresses another common problem in distributed computing, a generic work queue container can be created and reused whenever this capability is required.