Tutorial exercises

From mi-linux
Jump to navigationJump to search

XML and Web Services >> Tutorial exerices

Tutorial: Week 2 – MVC & Controllers

  • Describe the roles of the model, view, and controller in the MVC design pattern as applied to web application development. Illustrate your answer with examples of each component.

MVC is an architectural pattern used in software engineering, however it is often used in a web applications. When designing an ecommerce web site you will be able to split it up to three, the model would be actual content of the page for example a database which will keep record of all the goods. The view would be the actual HTML page where the user will interact with and finally the controller is the code which gathers data to generate the content for the page for example getting the customers order (shopping cart).

Wikii.jpg
  • Describe what is meant by ‘URL rewriting’ and list the main advantages of its use. Explain why the use of controllers eases the process, and how it aids in creating RESTful applications.

A rewrite engine is a piece of web server software used to modify URLs before fetching the requested item, for a variety of purposes. This technique is known as URL rewriting. Some benefits derived from a rewrite engine are:

Making website URLs more user and search engine friendly. Preventing undesired "inline linking" or "hot linking" Not exposing the (web address-related) inner workings of a website to users

**This is incomplete - someone please answer question part 2 - how do controllers ease the process of url rewriting, and how do they aid in creating restful applications. You can remove this when you edit the answer

  • Describe the basic principles of the REST architecture (Fielding, 2000). Explain, with examples, how to implement a RESTful web application using Ruby on Rails.

REST: Representational State Transfer. It is refer to a collection of network architecture principles that outlines how resources are defined and addressed. Principles: •Application state and functionality are divided in to resources •REST architecture requires that applications use a simple, limited and repeatable set of verbs to perform actions on data and resources •All resources share a uniform interface for the transfer of state between client and resources consisting of well-defined operations and content types supporting code on demand.

Systems which follow Fielding’s REST principles are often referred to as “RESTful”. Ruby on rails is a free web application frame. It has application server built in and these application servers provide authentication, authorization, state handling, error handling, logging and performance which can be used to implement a web application.

Tutorial: week 3 – Models & ORM

  • Describe the characteristics of object and relational models that give rise to the problem known as ‘impedance mismatch’. Suggest two solutions, and describe one in detail, with examples where appropriate.

Impedance mismatch is a situation that arises when attempting to combine an object oriented software model with a relational database. Both the area of database design, and the area of software design have developed in completely separate ways, and as such, the differences between them can cause problems.

Objects in OO programs have identity, behavior and state whereas relational databases do not, this fact means databases and oo software need to "map" the data to each other, which in turn may cause slowdown. Also while Object Oriented programs use encapsulation to hide the way the programs work, mapping this implementation data to a relational database makes the database fragile as it has the potential to reveal the way the underlying software works.

One solution to solving impedance mismatch is simply to use an object oriented database system instead of a relational database, however, in reality this is often not a valid alternative as most databases used in the real world are relational.

Another option is to use a process called "object relational mapping". This is a technique used to convert data between incompatible type systems in relational databases and object-oriented programming languages. If object relational mapping is used, it is possible to use objects as tuple attribute values. This means that custom data types (such as a programmer created data class) can be used within a relational database. This technique essentially "extends" that of the relational database using DB adapters to wrap and encapsulate the database access. In ruby, the ActiveRecord design pattern is used to implement this.

  • Describe the ActiveRecord design pattern and explain how it is implemented in Ruby on Rails.

Active record pattern is a design pattern that is used in many enterprise applications.

Active record is about accessing data in a database. A database table is put into a class, this means that an object is assigned to a row in the database table. When an object is created, a new row is then added to the database table, when it is saved. Objects when loaded, recieves its information from the database. Also when an object is updated, the row that it's connected to in the database table gets updated aswell.

The Ruby on Rails ActiveRecord is implemented by object relational mapping - This means that data and logic are put together in one package. Object-Relational Mapping is a technique for changing data between unsuited systems in relational database so that it can be used in the programming languages.

  • Discuss the advantages and disadvantages of Rails migrations as an approach to model maintenance. What techniques does it provide to deal with different database cardinalities?

== Rails Migrations == The advantages of rails migrations are; 1) No SQL knowledge. 2) All changes controlled via rake. 3)creat two versions in migration - file "self.up" which is for new versions and file "self.down" for rollback. 4)Migrations can modify and populate a database.

The disadvantages of rails migrations are;"I stress there wasn't many i could find!" 1) Only supports primitive data types e.g integer.

Technigues rails supports scaffolds and automatically creates basic maintainenarece pages. Technigues that represent different cardinalities are e.g M:N relationships.

Tutorial: Week 4 – Views & Templates

  • List and explain the benefits of the View component of the MVC paradigm. Discuss why templates are commonly used as a central part of the view component.


Benefits of the view component: 1) The view is separate from the main body of code, meaning if you edit the view it won't affect the rest of the application. 2) Using the different views and controllers you can have many different views for one model, meaning the user(or browser) can choose the one it likes best. 3) by adding a few lines in the view you can make it check to see if the user has access to those items and so can decide what the user can see on the page.

Templates are often used as the central part of the view component as it saves typing out HTML (or XHTML) for each of the pages. The one template can be used to hold the information of all the other pages by using the simple <%= yield %> reducing development time and the reuse of code. Templates also save on errors in XHTML validation, since if the XHTML is valid in that, and all the pages use it then the XHTML is likely to be valid on all pages.


  • Describe the function of a Template Markup Language in a template system. List the main requirements, with examples, of suitable candidates for such a language. What are the main factors that decide whether the language should be programming language based, or independent?

Template Markup Language is the language used in templates. Template Markup Language can be programming language specific or independent.

Main Requirements: 1) Must be able to define variables. 2) Must support variable substitution. 3) Needs flow control directives to specify conditional content.

Examples of Template Markup Languages: Python, JavaScript, Ruby(erb)

Main factors that decide which kind of language to be used:1) Familiarity 2) Flexiblity 3) Support availablity.

  • Ruby on Rails provides helper methods to reduce the dependency on code embedded in templates. Explain the reasons for this provision, giving examples of helpers and how they might be used.

Helpers are methods that have been created to be automatically used in the view. These can be used to keep the programming code out of the view and so that you can see the view code more easily. They can be written by the programmer or found online. Online you can find a wide range of downloadable helpers. Some of helpers I found were sort helpers. These can be used to sort data from a database. Many of them had clickable headers so that the user can sort the data them self’s, in what ever order they choose. I also found helpers that display a calendar on the screen if a date needed to be entered. E.G. if you had to enter you DOB then you would just click on the date and it would be entered for you. This may reduce the risk of typing errors.

Tutorial: Week 5 – testing

  • Define the terms testing, error and test case – explain how these definitions relate to web applications and the differences between testing traditional software applications and web applications.

Testing is a means to evaluate the quality of an application by finding bugs/defects so the problem can be fixed. In other words, it is a process to find any weaknesses in the work product. An Error can be considered to be a deviation from the expected value. The term test case means a set of test inputs, execution conditions, and expected results developed to test features of the application.


  • Describe the Ramler (2002) test cube and how it can be applied to web application testing.

Ramler states that the three dimensions (quality, feature & phase) can be combined to form a cube. The three dimensions form the axes of the cube.

The quality dimension includes four characteristics: 1. Functionality 2. Reliability 3. Usability 4. Efficiency

The feature dimension includes three categories: 1. Functions 2. Content 3. Infrastructure & Environment

The phase dimension includes three steps: 1. Specification & Development 2. Testing & Installation 3. Operation & Maintenance

The points of intersection in the cube can then be used to include the appropriate tests at the correct points. Certain tests may appear in more than one point in the cube as each test may cover more than one quality aspect. The cube can be fine-tuned to the specific application being developed, and each category can be further split into other sub-categories. For example, the Functionality characteristic of the Quality dimension can be further divided into Suitability, Accuracy, Security and others. This process can be extended to all characteristics of all three dimensions, forming a solid test plan. A sample cube is shown below.

Cube.jpg

  • Describe the specifics of web application testing, explain which elements could be automated and suggest possible tools that could be used for the process.

Tutorial: Week 6/7 – Comparisons

  • Web frameworks are a relatively new approach to agile web application development. Discuss the concepts involved in creating a framework, illustrating your answer with examples of a real framework.
  • Compare and contrast two web frameworks that you are familiar with. Give examples of components that are utilised to illustrate your answer.

-Daniel Dawes 0601163-

Ruby on Rails (Hereby RoR) vs Cake-PHP

  • Discuss the design patterns that are used as the basis of web frameworks, highlighting any compromises or issues encountered in the implementation.

Tutorial: week 9 – XML

  • Discuss the advantages and disadvantages of XML as a data exchange format in comparison with one other commonly used format.

XML can be used as a data exchange format and has the following advantages.

• It is established and supports syntax standards • It is a common program interface for reading and writing XMl text • It is a flexible data structure • It is a web enabled technology.

Like everything, XML also has its disadvantages and these are shown below.

• Unlike usual database, XML text does not have fixed structure.

 In most cases whole XML text stored in memory, so it should 
 be relatively small files.

• There are no built-in security in XML, so you have to encrypt

 and decrypt XML files.

• XML is text format so you have to convert all fields to text

 type before storing in text.

The information was taken from the following website :

http://www.delphi3000.com/articles/article_515.asp?SK=

  • There are two mechanisms available to constrain an XML file. Compare both and discuss the advantages and disadvantages of each approach.
  • Explain how to create an XML file using the Rails framework, and describe two applications for such a file.

Tutorial week 10 - Web 2.0

  • “Web 2.0 is more of a social or business evolution than a technical one.” Discuss this assertion with respect to the common technologies that Web 2.0 applications employ.

Web 2.0 is more of a social development than a technical one. The web has become not only a place to find information on a certain subject but to find someone and share any number of things. The web has and web 2.0 use the same hardware but in different ways. Sites such as MySpace and YouTube are sites which contain uploaded content from normal users. These sites are simple in theory but without the support of users these sites would be worthless and empty.

Web 2.0 relies on programmes that update a server full of information from multiple users like YouTube. Weblogs, wiki’s, forums and mash ups are three different ways that Web 2.0 is used. If you wish to use a Web 2.0 site and learn more about Web 2.0 then visit http://en.wikipedia.org/wiki/Web_2.

  • Web 2.0 is also known as the ‘collaborative web’. Describe which technologies make this possible, and indicate how these technologies are supported in Rails.

The technologies that collaborate together to form what is known as Web 2.0 includes Web Content Syndication (RSS, Web Feed), Messaging Protocols (XMPP/Jabber), and Server Software (Apache), among others.

Ruby supports the use of RSS feeds by acting as an object orientated library, that parses, creates, downloads, and caches RSS's. Examples of RSS feed code can be found at www.rubyrss.com.

The eXtensible Messaging and Presence Protocol (XMPP) is the messaging protocol formerly known as Jabber. XMPP uses XML code, and can be used for Instant Messaging (including file transfer) and Voice over IP applications. XMPP4R is an XMPP library project to provide frameworks for creating applications and scripts in Ruby. As it is coded in Ruby, it is object orientated, making it easier for the user.

The ModRuby project is currently in development, which aims to integrate Ruby with the server software package Apache.

  • Web 2.0 and XML go together like ‘bread and butter’. Discuss this assertion with reference to RSS and AJAX. How do these technologies contribute to the Web 2.0 approach?

XML is used to transfer data in web technologies such as RSS (Really Simple Syndication) and AJAX (Asynchronous JavaScript and XML) in a Web 2.0 application. This helps Web 2.0 provide characteristics such as rich user experience and dynamic content. RSS is a common feature/technique used in web 2.0 applications to permit the use of a website’s data to be used in another context such as another website or even a browser plug-in. RSS files are created using XML and therefore enables web 2.0 applications to publish frequently updated content. AJAX is a rich-internet application technique used in Web 2.0 to improve user experience. It works by using XML to transfer data requests, by calling AJAX functions, in JavaScript on the client side to a server side scripting language. This takes place in the ’background’ so the view, in terms of MVC, is not interfered with. This helps Web 2.0 applications increase their interactivity, speed, functionality, and usability.

These Technologies contribute to the Web 2.0 approach in a number of ways. RSS allows data to be shared with individuals or with other websites, therefore supporting collaboration. This means that a web developer can use data via an RSS feed to help create a custom web application. An example of RSS in action is when a web developer creates a ‘latest news’ webpage using several RSS feeds to gather the latest news information. AJAX is used to give a rich user experience. Examples of AJAX integration in web development can be seen in [1] and in [2]. These websites allow web applications to behave more like desktop applications, in that you can ‘drag and drop’ items, so you are able to customize the webpage to your personal taste. AJAX allows asynchronous web applications, you get faster response times. Also used to improve user experience e.g. web-page requests an update for some part of its content which requires altering the webpage in the browser. This can be achieved without the need to refresh the whole page using AJAX. These technologies contribute to the Web 2.0 approach by allowing the creation of rich user interfaces.

Tutorial week 11 - Web services

  • Explain what is meant by the term ‘web services’ and the role they play in a distributed computing system. Compare and contrast them with Corba, explaining the acronym and the advantages and disadvantages of each.
  • Modern web services can be implemented via a RESTful approach or via SOAP. Discuss the advantages and disadvantages of each approach.
  • A service oriented architecture (SOA) is one approach to the enterprise application of web services. Discuss how web services fit into a SOA, and explain what supplementary services/ components are required to form a true SOA.