~~SLIDESHOW~~
Contact Hour 22: To be discussed on Tuesday 16th April, 2013.
Lecturer: Dr Chris P. Jobling.
An introduction to frameworks for web application development using Ruby on Rails as an exemplar.
At the end of this lecture you should be able to answer these questions:
At the end of this lecture you should be able to answer these questions:
At the end of this lecture you should be able to answer these questions:
At the end of this lecture you should be able to answer these questions:
The idea of this architectural structure is that each tier can independently developed and changed if necessary. Thus the client is independent of changes to the server and the server is itself independent of the database. Each tier may exist on the same physical host or may be separated by a network connection.
In the case of the web implementation of the client tier in which part exists in a web browser separated from a web server by a network connection. In the latter situation it is most likely that the middle tier will be co-located with the web server, but it doesn't have to be, and indeed may need to be separated due to non-functional issues such as scalability.
The limitations of HTTP and the design of browser technology makes the web tier a complex animal.
For example, the modern browser model requires that the client layer is broken into the three layers:
Arguably, additional layers are introduced by the use of DOM in Dynamic HTML and Asynchronous operation introduced by AJAX.
Of course, each layer is defined in some form of computer programming language has its own formal syntax which needs to be mastered by the web applications developer.
The server layer itself adds its own complexities.
See the additional notes for an example of how this is done for PHP.
For example CGI, server-side include technology like PHP, Java servlets. In the simplest cases, the middle-tier is no more than a thin wrapper to the data-access layer. In others, a more sophisticated model is used. A common idiom requires that the data-access layer needs provides sophisticated support that allows objects to be instantiated from database records (usually by some form of mapping of record fields to object properties) and writing the properties back to the database when the object state is changed by the client layer. Of course, however it is implemented, there is at least one programming language and set of programming idioms in operation in the middle-tier layer and often there is more than one.
In many implementations of web applications, there is yet another pair of layers that are added. These integration layers are often written in XML and define mappings between the middle tier and the other tiers. Two examples of how these integration layers are used are:
The fact that the integration definitions are written in yet another programming language adds yet another level of complexity to web application development.
<note>
</note>
Language | Example Frameworks | Total number |
---|---|---|
Java | Cocoon, Struts, Tapestry, Grails, Wicket, JSF, GWT | 28+ |
ASP.NET | MonoRail, DotNetNuke, CSLA | 3+ |
ColdFusion | ColdSpring, Fusebox, Mach-II, Model-Glue | 4+ |
Perl | Catalyst, Mason, Maypole, Interface | 4+ |
PHP | Drupal, CakePHP, Zend Framework, Lavarel | 21+ |
Python | CherryPy, Django, Zope, TurboGrears, TwistedWeb | 11+ |
Ruby | Ruby on Rails, Sinatra | and others |
JavaScript | Meteor, Node.js | some others |
Web frameworks is a very crowded market with, as you can see here, a large selection of frameworks for each choice of base language. This makes choice of framework a challenge! However, one advantage is that many frameworks are open-source projects, so one can make a choice based on the size of the development community, project activity, quality of documentation, pedigree etc. The emergence of AJAX and Ruby on Rails has created some shaking up of the market place over the past three years.
In attempt to cope with complexity, several design patterns have emerged for web applications. The main ones that commonly come up in frameworks are:
Web Tier is essentially a good example of the classic model-view-controller (MVC) pattern.
* Used when navigation and application logic is more complex than can be reasonably handled by a collection of page controllers.
The front controller works as follows:
The idea of this pattern is that the application developer is able to define the web user interface components as he/she would a conventional desktop user interface component and handle the HTTP request as if it was a conventional event. A great deal of framework support is required to maintain the fiction of a component-based event-driven architecture over the realities of the web tier. But if it can be made to work, this is s a pattern that is very familiar to developers from other application development domains, e.g. Visual Basic and Java Swing. The best supported examples of this pattern are Java Server Faces (JSF), Apache Tapestry and the Google Web Toolkit. All Java frameworks!
Writing a program that spits out HTML is often more difficult than you might imagine. Although programming languages are better at creating text than they used to be (some of us remember character handling in Fortran and standard Pascal), creating and concatenating string constructs is still painful. If there isn't much to do, it isn't too bad, but a whole HTML page is a lot of text manipulation.
With static HTML pages—those that don't change from request to request—you can use nice WYSIWG editors. Even those of us who like raw text editors find it easier to just type in the text and tags rather than fiddle with string con-catenation in a programming language.
Of course the issue is with dynamic Web pages – those that take the results of something like database queries and embed them into the HTML. The page looks different with each result, and as a result regular HTML editors aren't up to the job.
The best way to work is to compose the dynamic web page as you do a static page but put in markers that can be resolved into calls to gather dynamic information. Since the static part of the page acts as a template for the particular response, Fowler calls this a Template View.
An object carries both data and behavior. Much of this data is persistent and needs to be stored in a database. Active Record uses the most obvious approach, putting data access logic in the domain object. This way all people know how to read and write their data to and from the database.
<note> Ruby itself is a pleasant language for application development:
Meta-programming:
</note>
<note>DRY means that definitions should only have to be made once. Since Ruby on Rails is a “full-stack” framework, the components are integrated so that bridges between them do not need to be set up manually. For example, in Active Record, class definitions need not specify the column names; Ruby can already find them from the database itself, so defining them in both the program and the Relational Database Management System (RDBMS) would be redundant.
“Convention Over Configuration” means that the programmer only needs to define configuration that is unconventional. For example, if there is a Post class in the model, the corresponding table in the database is posts. (Note that Ruby on Rails automatically pluralizes the table name based on the model name.) Thus, using Rails' conventions when developing a web application from the ground up reduces the amount of code that needs to be written. </note>
Rails makes use of the following design patterns:
<note> Implementation notes:
</note>
History of Rails Development:
[1] Web application framework, From Wikipedia, the free encyclopedia.
[2] List of web application frameworks, From Wikipedia, the free encyclopedia
[3] Martin Fowler, Patterns of Enterprise Application Architecture, Addison Wesley Signature Series, Addison Wesley, 2002.
[4] Martin Fowler, Patterns of Enterprise Application Architecture: Catalogue, MartinFowler.com, URL: http://www.martinfowler.com/eaaCatalog/index.html.
[5] Ruby on Rails, From Wikipedia, the free encyclopedia.
[6] Curt Hibbs, Rolling with Ruby on Rails, O'Reilly Media Inc, January 20, 2005.
[7] Dave Thomas and David Heinemeier Hansson, Agile Development with Rails, 1st Ed., Pragmatic Bookshelf, July 2005.
[8] Michael Hartl, Ruby on Rails Tutorial: Learn Rails by Example, Addison Wesley, 2010 and online at ruby.railstutorial.org.
At the end of this lecture you should be able to answer these questions:
At the end of this lecture you should be able to answer these questions:
At the end of this lecture you should be able to answer these questions:
At the end of this lecture you should be able to answer these questions: