
Layering and Abstraction in Computer Science
Exploring the concepts of layering and abstraction in computer science, this content delves into tiered architectures, PHP scripting, and the importance of hiding working details for interoperability and platform independence. Discover how computing thrives on abstraction to create efficient problem-solving models.
Download Presentation

Please find below an Image/Link to download the presentation.
The content on the website is provided AS IS for your information and personal use only. It may not be sold, licensed, or shared on other websites without obtaining consent from the author. If you encounter any issues during the download, it is possible that the publisher has removed the file from their server.
You are allowed to download the files provided on this website for personal or commercial use, subject to the condition that they are used lawfully. All files are the property of their respective owners.
The content on the website is provided AS IS for your information and personal use only. It may not be sold, licensed, or shared on other websites without obtaining consent from the author.
E N D
Presentation Transcript
UFCFR3-30-1 Information Technology 2020-21 Lecture 4: Tiered Architecture & Further PHP
so far in lectures o nature of computation, models of computing (Turing & Church); o Von-Neuman Architecture, low-level / high-level languages; o imperative programming, compiling and interpreting; o overview of mark-up languages; o different markup languages: html, kml, sgml, xhtml etc.; o html5 history and syntax; o new features in html5: video, audio, svg, canvas etc.; o php as a scripting language; (supporting procedural, functional & oo paradigms); o php s basic structure & use (statements, variables, control structures & operators).
so far in workshops o required software installation; o environment tests & validation; o PHP calculator exercise; o html5 syntax and formatting exercise; o html5 input form syntax and input validation; o php response to form parameters.
this lecture o abstraction; o layering & tiering in computer science and systems engineering; o layering examples; o two-tier & three-tier architectures; o advantages of three-tier architectures; o web-oriented three-tier and n-tier architectures; o tools and technologies for each tier; o php functions; o php environment variable o simple form example using $_GET;
abstraction in computing: In computing, an abstraction layer or abstraction level is a way of hiding the working details of a subsystem, allowing the separation of concerns to facilitate interoperability and platform independence. Examples of software models that use layers of abstraction include the OSI model for network protocols, OpenGL and other graphics libraries. The notion of abstraction is used in many other ways in computing. For instance models such as entity-relationship (ER) models are also abstractions of the underlying database. Programming languages are abstractions of the underlying machine code (binary) which have to be compiled or interpreted before executing.
computing as abstraction: Computer Science is a science of abstraction - creating the right model for a problem and devising the appropriate mechanizable techniques to solve it. - A. Aho and J. Ullman Any programming problem can be solved by adding a level of indirection (abstraction). - Anonymous
abstraction example 1: Internet Protocol
abstraction example 2: OSI Network Layers
multitier architecture: In software engineering, multi-tier architecture (often referred to as n-tier architecture) is a client server architecture in which presentation, application processing, and data management functions are logically separated. For example, an application that uses middleware to service data requests between a user and a database employs multi-tier architecture. The most widespread use of multi-tier architecture is the three-tier architecture. N-tier application architecture provides a model by which developers can create flexible and reusable applications. By segregating an application into tiers, developers acquire the option of modifying or adding a specific layer, instead of reworking the entire application. Three-tier architectures typically comprise a presentation tier, a business or data access [logic] tier, and a data tier. (Wikipedia : Multitier Architecture)
two-tier architecture: A two-tier architecture is a software architecture in which a presentation layer or interface runs on a client, and a data layer or data structure gets stored on a server. Separating these two components into different locations represents a two-tier architecture, as opposed to a single-tier architecture.
advantages of the 3-tier architecture approach: o the ability to separate logical components of an application ensures that applications are easy to manage and understand. i.e. experts can be employed that specialise in one of the layers e.g. user interface design o because communication can be controlled between each logical tier of an application, changes in one tier, for example, the database access tier, do not have to affect the client component i.e. a change from one DBMS to another would only require a change to the component in the data access layer with little or no effect on the business/logic (middle) or UI layer. o specific tools and technologies suited to each layer can be deployed (and may evolve at a different pace) .
web-oriented 3-tier architecture (php example) Web Services
Web-oriented 3-tier architecture: tools & technologies oPresentation tier Browser / custom client, Client Side Scripting (JavaScript), Applets. o Logical Tier Web Server (Apache, IIS, Websphere etc.); Scripting Languages (PHP, Perl etc.), Programming Languages (Java, Python, C, C# etc), Application Frameworks (Ruby on Rails, Symfony etc.) oData Tier Database Management System (DBMS) (Oracle, MySQL, SQL Server, DB2 etc.), XMLDB, NoSQL DB.
PHP Functions (1) : inbuilt function library (700+) oBasic tasks String Handling Mathematics random numbers, trig functions.. Regular Expressions Date and time handling File Input and Output oAnd more specific functions for - Database interaction - MySQL, Oracle, Postgres, Sybase, MSSQL .. Encryption Text translation Spell-checking Image creation XML etc.etc.
PHP Functions (2) : some commonly used built-in functions Function Purpose Example echo() prints text echo "Hello World"; explode() returns a string as an array split on the specified delimiter $pizza = "piece1 piece2 piece3"; $pieces = explode(" ", $pizza); echo $pieces[1]; // piece2 implode() opposite of explode joins all the elements of an array using the specified delimiter $array = array('lastname', 'email', 'phone'); $comma_separated = implode(",", $array); //prints lastname,email,phone echo $comma_separated; isset() returns TRUE if a variable exists or FALSE if not isset($a); fopen() $filename = "myfile.txt"; $handle = fopen($filename, "r"); $contents = fread($handle, filesize($filename)); fclose($ini_handle); opens a file for reading ( r ) or ( w ) writing. Use in conjunction with fclose.
PHP Functions (3) : some useful functions during development exit()and die(): aliased functions; exit() used to stop execution (good during debugging) & die() for error. print_r(): prints the values of an array. var_dump(): dumps data about a variable.
Environment & other predefined variables (1) o PHP provides a large number of predefined variables to all scripts. o These variables represent everything from external variables to built-in environment variables, last error messages to last retrieved headers. $GLOBALS References all variables available in global scope $_SERVER Server and execution environment information $_GET HTTP GET variables $_POST HTTP POST variables $_FILES HTTP File Upload variables $_REQUEST HTTP Request variables $_SESSION Session variables $_ENV Environment variables $_COOKIE HTTP Cookies $php_errormsg The previous error message $HTTP_RAW_POST_DATA Raw POST data $http_response_header HTTP response headers $argc The number of arguments passed to script $argv Array of arguments passed to script
Environment & other predefined variables (2) o Some predefined variables are available to every script in every scope (both local and global) and these are referred to as Superglobals. o For these, there is no need to do global $variable; to access them within functions or methods. o The superglobals are: $GLOBALS $_SERVER $_GET $_POST $_FILES $_COOKIE $_SESSION $_REQUEST $_ENV
Environment & other predefined variables (3): the $_GET & $_POST & $_REQUEST globals o The most commonly used global variables are $_GET and $_POST which are used to send data from the browser to the server. o $_GET is an associative array (hash) that passes values to the current script using URL parameters. - although the HTTP protocol does not set a limit to how long URL s can be different browsers do so it is considered good practice not to send data that is more than 2000 characters with $_GET - because the values of $_GET can be read in the URL no data containing sensitive information (like passwords) should be sent using $_GET - $_GET can't be used to send binary data, like images or word documents, just textual data.
PHPs Environment & other predefined variables (4): $_GET example checks if either the name or age params. have values set <?php if(isset($_GET["name"]) || isset($_GET["age"])) { echo "<p>Welcome ". $_GET['name']. "<br/>"; echo "You are ". $_GET['age']. " years old.</p>"; exit(); } ?> <html> <body> <form action="<?php $_PHP_SELF ?>" method="GET"> Name: <input type="text" name="name" /> Age: <input type="text" name="age" /> <input type="submit" /> </form> </body> </html> $PHP_SELF returns path and name of current script html form with 3 inputs form method set to GET run script ** Notice that once the form fields are filled in with values of say Popeye and 83 , the URL shows as http://host/path/get_example.php?name=Popeye&age=83 i.e. the parameters are now part of the URL.
Environment & other predefined variables (5): $_POST & $_REQUEST o The POST method transfers information via HTTP headers. - the POST method does not have any restriction on data size to be sent. - it can be used to send ASCII as well as binary data. - the data sent by POST method goes through HTTP header so security depends on HTTP protocol. By using Secure HTTP (HTTPS) the data can be secured (to a certain extent). - PHP provides the $_POST associative array to access all the sent data using the POST method. ** Note that the example used in the previous slide can be easily changed to make use of the POST method by simply changing the method="GET" to method="POST". The parameters no longer appear in the URL. view script run script o $_REQUEST is an associative array (hash) that by default contains all of the contents of $_GET, $_POST and $_COOKIE together. ($_COOKIE superglobal will be discussed when we consider PHP sessions).