2/20 - Software Architecture Flashcards
Model View Controller (MVC) Architecture
- A method for separating the user interface of an application from its domain logic.
- UI and domain logic have different drivers for change and rates of change.
The Model
- The model is the functional core of the application
- Encapsulates the state of the application
- Model is independent of the GUI
- Active Model
- Passive Model
Functional core of the application
- Business logic
2. Domain logic
Business logic
business layer in enterprise applications
Domain logic
domain-specific logic
The State of the application
- Example: databases
- Invariants (e.g. a transaction in a zero-sum operation)
- If model is correct the data will continue to make sense
Model is independent of the GUI
- It cannot direct references to the view or controller
- This gives it flexibility, testability and robustness
- Model can be tested using automated controller and machine checkable views
Active Model
- Defines a change notification mechanism that view and controller can subscribe to
- Common in desktop GUI apps
Passive Model
- Model is called by view and controller to get data
* Common in web UI
The View
- What data to show and how to present it based on the state of the model
- View informs the controller of user actions
- View has access to the model but should not change the model
- For web apps, view contains HTML + Javascript
The Controller
- View deals with output, Controller deals with input
- Controller decides what model actions are needed, selects the next view and allows user to drive the app
- In web apps, controller will be handler for incoming HTTP requests
Pros of MVC
- Allows to separate and modularize concerns. Leads to ease of development, testing and maintenance
- Separation between data layer and interface is the key
Why is separation between data layer and interface key?
- View is easily replaced or expanded
- Model data changes are reflected in views
- Better scalability
- Distribution over network is greatly simplified
Cons of MVC
- View and Controller depend heavily on model API
- Close coupling between view and controller
- Additional complexity
Architectural Configurations
Arrangements of components and connectors to form an architecture
Examples of Architectural Configurations
MVC, Pipe and Filter, Layered Systems, Event based Systems
Example of Pipe and Filter Architecture
Unix Shell commands
Components of Pipe and Filter Architecture
filter transform input into output
Connectors of Pipe and Filter Architecture
data stream
Other examples of Pipe and Filter Architecture
compilers, batch data processing
Pros of Pipe and Filter Architecture
- Overall behavior is understood as a simple composition of the behaviors of the individual filters
- Support reuse. Existing filters can be hooked up to form a system
- Modular testing
- Easy maintenance and enhancement
- Supports specialized analysis (throughput or deadlock analysis)
- Supports parallel or distributed execution
Cons of Pipe and Filter Architecture
- Not good for handling interactive apps
- Sometimes we need tighter coupling of filter for better performance
- Extra overhead to parse and unparsed data to an external format
Example of a special case of pipe -filter
Map-Reduce
Layered Architecture
Each layer provides a higher level of abstraction to the layer above