Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...

Full Transcript

**Week 7** Integrative Coding **Lesson Title** **Design Patterns and Interfaces** **Learning Outcome(s)** Define the importance of using design patterns, describe what is a programming interface and its importance **Software Design Pattern** a description or template for how to solve a problem...

**Week 7** Integrative Coding **Lesson Title** **Design Patterns and Interfaces** **Learning Outcome(s)** Define the importance of using design patterns, describe what is a programming interface and its importance **Software Design Pattern** a description or template for how to solve a problem that can be used in many different situations. **Interaction** is a kind of action that occurs as two or more objects have an effect upon one another. The idea of a two-way effect is essential in the concept of interaction, as opposed to a one-way causal effect **Best Practice** a standard way of complying with legal or ethical requirements. **Object-oriented design** Patterns that imply mutable state may be unsuited for functional programming languages. ***Software Design pattern*** A **software design pattern** is a general, reusable solution to a commonly occurring problem within a given context in software design. It is not a finished design that can be transformed directly into source or machine code. Rather, it is a description or template for how to solve a problem that can be used in many different situations. Design patterns are formalized best practices that the programmer can use to solve common problems when designing an application or system. **Object-oriented design** **patterns** typically show relationships and interactions between classes or objects, without specifying the final application classes or objects that are involved. Patterns that simply mutable state may be unsuited for functional programming languages, some patterns can be rendered unnecessary in languages that have built-in support for solving the problem they are trying to solve, and object-oriented patterns are not necessarily suitable for non-object-oriented languages. **A best practice** is a method or technique that has been generally accepted as superior to any alternatives because it produces results that are superior to those achieved by other means or because it has become a standard way of doing things, e.g., a standard way of complying with legal or ethical requirements. - Design patterns can speed up the development process by providing tested, proven development paradigms - Effective software design requires considering issues that may not become visible until later in the implementation. - Freshly written code can often have hidden subtle issues that take time to be detected, issues that sometimes can cause major problems down the road. - Reusing design patterns helps to prevent such subtle issues, and it also improves code readability for coders and architects who are familiar with the patterns. ***Classification and List*** - Design patterns had originally been categorized into 3 sub-classifications based on kind of problem they solve. - **Creational patterns** provide the capability to create objects based on a required criteria and in a controlled way. - **Structural patterns** are about organizing different classes and objects to form larger structures and provide new functionality. - **Behavioral patterns** are about identifying common communication patterns between objects and realize these patterns. ***Uses of Design Pattern*** Design patterns can speed up the development process by providing tested, proven development paradigms. Effective software design requires considering issues that may not become visible until later in the implementation. Reusing design patterns helps to prevent subtle issues that can cause major problems and improves code readability for coders and architects familiar with the patterns. Often, people only understand how to apply certain software design techniques to certain problems. These techniques are difficult to apply to a broader range of problems. Design patterns provide general solutions, documented in a format that doesn\'t require specifics tied to a particular problem. ***Creational Pattern*** These design patterns are all about class instantiation. This pattern can be further divided into class-creation patterns and object-creational patterns. While class-creation patterns use inheritance effectively in the instantiation process, object-creation patterns use delegation effectively to get the job done. **Abstract Factory** **Intent** **Discussion** **Example** ***https://sourcemaking.com/files/v2/content/patterns/Abstract\_Factory\_example1.png*** **Builder Design** **Intent** **Problem** **Discussion** **Example** *https://sourcemaking.com/files/v2/content/patterns/Builder\_example1.png* ***Structural Design Pattern*** These design patterns are all about Class and Object composition. Structural class-creation patterns use inheritance to compose interfaces. Structural object-patterns define ways to compose objects to obtain new functionality. **Adapter Design** **Intent** **Problem** **Discussion** **Example** ![](media/image3.png) *https://sourcemaking.com/files/v2/content/patterns/Adapter\_example1.png* **Bridge Design** **Intent** **Problem** **Discussion** *Use the Bridge pattern when:* - you want run-time binding of the implementation, - you have a proliferation of classes resulting from a coupled interface and numerous implementations, - you want to share an implementation among multiple objects, - you need to map orthogonal class hierarchies. *Consequences include:* - decoupling the object\'s interface, - improved extensibility (you can extend (i.e. subclass) the abstraction and implementation hierarchies independently), - hiding details from clients. **Example** ***Behavioral Design Pattern*** These design patterns are all about Class\'s objects communication. Behavioral patterns are those patterns that are most specifically concerned with communication between objects. **Chain of Responsibility** **Intent** **Problem** **Discussion** **Discussion** **Command Design** **Intent** **Problem** **Discussion** **Example** ***API (Application Programming Interface)*** is a computing interface which defines interactions between multiple software intermediaries. It defines the kinds of calls or requests that can be made, how to make them, the data formats that should be used, the conventions to follow, etc. It can also provide extension mechanisms so that users can extend existing functionality in various ways and to varying degrees. An API can be entirely custom, specific to a component, or it can be designed based on an industry-standard to ensure interoperability. Through information hiding, APIs enable modular programming, which allows users to use the interface independently of the implementation. In building applications, an API (application programming interface) simplifies programming by abstracting the underlying implementation and only exposing objects or actions the developer needs. While a graphical interface for an email client might provide a user with a button that performs all the steps for fetching and highlighting new emails, an API for file input/output might give the developer a function that copies a file from one location to another without requiring that the developer understand the file system operations occurring behind the scenes. **Software quality** refers to two related but distinct notions: - Software functional quality reflects how well it complies with or conforms to a given design, based on functional requirements or specifications. That attribute can also be described as the fitness for purpose of a piece of software or how it compares to competitors in the marketplace as a worthwhile product. It is the degree to which the correct software was produced. - Software structural quality refers to how it meets non-functional requirements that support the delivery of the functional requirements, such as robustness or maintainability. It has a lot more to do with the degree to which the software works as needed. ------------------------- ---------------------------------------------------------------------------------------------------------------------- **Week 8** Integrative Coding **Lesson Title** **OOP preview** **Learning Outcome(s)** Differentiate classes and objects, apply calling methods and explain the significance of object instances in program ------------------------- ---------------------------------------------------------------------------------------------------------------------- **Software Design Pattern** a description or template for how to solve a problem that can be used in many different situations. **Interaction** is a kind of action that occurs as two or more objects have an effect upon one another. The idea of a two-way effect is essential in the concept of interaction, as opposed to a one-way causal effect **Best Practice** a standard way of complying with legal or ethical requirements. **Object-oriented design** Patterns that imply mutable state may be unsuited for functional programming languages. **Essential Content** ***Define a Class*** A **class** is defined by using the class keyword, followed by the name of the class and a pair of curly braces ({}). All its properties and methods go inside the braces: Below we declare a class named Fruit consisting of two properties (\$name and \$color) and two methods set\_name() and get\_name() for setting and getting the \$name property: ***Define Objects*** Classes are nothing without objects! We can create multiple objects from a class. Each object has all the properties and methods defined in the class, but they will have different property values. Objects of a class is created using the new keyword. In the example below, \$apple and \$banana are instances of the class Fruit: In the example below, we add two more methods to class Fruit, for setting and getting the \$color property: ***PHP - The \$this Keyword*** The \$this keyword refers to the current object, and is only available inside methods. Look at the following example: So, where can we change the value of the \$name property? There are two ways: 1\. Inside the class (by adding a set\_name() method and use \$this): 2\. Outside the class (by directly changing the property value): ***PHP - What is Inheritance?*** Inheritance in OOP = When a class derives from another class. The child class will inherit all the public and protected properties and methods from the parent class. In addition, it can have its own properties and methods. An inherited class is defined by using the extends keyword. Let\'s look at an example: **Example Explained** The Strawberry class is inherited from the Fruit class. This means that the Strawberry class can use the public \$name and \$color properties as well as the public \_\_construct() and intro() methods from the Fruit class because of inheritance. The Strawberry class also has its own method: message(). ***PHP -- PHP Functions?*** **PHP User Defined Functions** Besides the built-in PHP functions, it is possible to create your own functions. A function is a block of statements that can be used repeatedly in a program. A function will not execute automatically when a page loads. A function will be executed by a call to the function. **Create a User Defined Function in PHP** A user-defined function declaration starts with the word function: In the example below, we create a function named \"writeMsg()\". The opening curly brace ( { ) indicates the beginning of the function code, and the closing curly brace ( } ) indicates the end of the function. The function outputs \"Hello world!\". To call the function, just write its name followed by brackets (): ***PHP -- PHP Functions Arguments*** Information can be passed to functions through arguments. An argument is just like a variable. Arguments are specified after the function name, inside the parentheses. You can add as many arguments as you want, just separate them with a comma. The following example has a function with one argument (\$fname). When the familyName() function is called, we also pass along a name (e.g. Jani), and the name is used inside the function, which outputs several different first names, but an equal last name: The following example has a function with two arguments (\$fname and \$year): ***PHP -- PHP Functions Arguments*** The following example shows how to use a default parameter. If we call the function setHeight() without arguments it takes the default value as argument: ***PHP -- PHP Functions Arguments*** To let a function return a value, use the return statement: ------------------------- ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ **Week 9** Scripting Language **Lesson Title** **Scripting Techniques** **Learning Outcome(s)** Identify key scripting language used for web scripting ,client-side scripting and server-side scripting. Explain the significance of client and server-side scripting for the rich web dynamic content in integration of software. ------------------------- ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ **Scripting Language** a series of commands that are able to be executed without the need for compiling **Interpreter** is a computer program that directly executes instructions written in a programming or scripting language, without requiring them previously to have been compiled into a machine language program.  **Compiler** is a computer program that translates computer code written in one programming language (the source language) into another language (the target language). **GCC** was originally written as the compiler for the [GNU operating system](http://www.gnu.org/gnu/thegnuproject.html).  ***Scripting Techniques*** A *scripting language* is a programming language that is interpreted, meaning it is translated into machine code when the code is run, rather than beforehand. Scripting languages are often used for short scripts over full computer programs. JavaScript, Python, and Ruby are all examples of scripting languages. Scripting language (also known as scripting, or script) is plainly defined as a series of commands that are able to be executed without the need for compiling. While all scripting languages are programming languages, not all programming languages are scripting languages. PHP, Perl, and Python are common examples of scripting languages.  Scripting language (also known as scripting, or script) is plainly defined as a series of commands that are able to be executed without the need for compiling. While all scripting languages are programming languages, not all programming languages are scripting languages. PHP, Perl, and Python are common examples of scripting languages.  ***Server-Side Scripting vs Client-Side Scripting*** There are two types of scripting languages: server side and client side. The only significant difference between the two is that the former requires a server for its processing. *Server-side scripting* languages run on a web server. When a client sends a request, the server responds by sending content via HTTP. In contrast, client-side scripting languages run on the client end---on their web browser. The benefit of *client-side scripts* is that they can reduce demand on the server, allowing web pages to load faster. Whereas, one significant benefit of server-side scripts is they are not viewable by the public like client-side scripts are. When trying to decide which way to go on a project, keep in mind that client-side scripting is more focused on user interface and functionality. Conversely, server-side scripting focuses on faster processing, access to data, and resolving errors. ***Examples of Server-Side Scripting Languages*** The following are examples of server-side scripting languages.  ---------- -------------------------------------------------------------------------------- Language Comments PHP The most popular server-side language used on the web. ASP.NET Web-application framework developed by Microsoft. Node.js Can run on a multitude of platforms, including Windows, Linux, Unix, Mac, etc. Java Used in everything from your car stereo's Bluetooth to NASA applications. Ruby Dynamic. Focuses heavily on simplicity. Perl A bit of a mashup between C, shell script, AWK, and sed. Python Great for beginners to learn. Uses shorter code. ---------- -------------------------------------------------------------------------------- ***Examples of Client-Side Scripting Languages*** The following are examples of client-side scripting languages. -------------- -------------------------------------------------------------------------------- **Language** **Comments** HTML The foundation of web development.  CSS Improves appearance and graphics on pages in your web browser. JavaScript Though typically client-side, can occasionally be used on server-side as well. -------------- -------------------------------------------------------------------------------- ***Applications of Scripting Languages*** What are scripting languages used for? Scripting languages are used in many areas, both on and off the web. In addition to server-side and client-side applications, scripting languages can be used in system administration. Examples of scripts used in system admin are Shell, Perl, and Python.  Scripting languages are also used in lots of games and multimedia. For example, Minecraft mods use Java to allow users to create their own worlds and items in the game. Additionally, Second Life, Trainz, and Wesnoth all allow users to create extensions on the games.  Similar to the extensions used in games, extensions in other programs, such as Google's Chrome browser extensions, are all run using scripting languages. ***Pros and Cons of Scripting Languages*** Pros. There are many benefits to using scripting languages over other programming languages. First, they are open-source. This allows users from around the world to join in the improvement process. Other pros include: No requirement to compile, although occasionally it is necessary. Easy to transfer between operating systems. Scripting languages make web pages look awesome. Easier to learn and write. Scripts can be used as a prototype to programs, saving time on test projects. Cons. There are not a whole lot of cons to using scripting languages. One con is the fact that some companies don't want scripts to be read by everyone, so they use server-side scripts to avoid releasing them to the public. Also, installing an interpreter program can be a hassle. Finally, sometimes scripts are slower than programs. ***What are the scripting techniques available for test automation?*** 1. **Linear scripting**\ - Here a simple record and playback is being used by a test engineer so as to automate a test flow/ test case of a system.\ - There can be some redundant functions etc which are not required.\ \ 2. **Structured scripting**\ - It is used to control structures in the scripts.\ - They enable the testers to control the flow of the test script/ test case.\ - They are typically 'if-else', 'switch', 'for', 'while' conditions/ statements which help in implementing the decision making in a script, to help perform some tasks iteratively and it has the capacity to call other common functions that need some common functionality 3. **Shared scripting**\ - Here the scripts represent an application behavior which is shared amongst other scripts.\ - The application which is under the test common functionality is scripted as shared scripts and these scripts are then called by other scripts.\ - The scripts become modular in terms of common functionality.\ - Due to the functionality of these scripts they cross the AUT boundary and can be used in other software applications as well.\ \ 4. **Data driven scripting**\ - The data is separated from the scripts and is stored into the external repository as disk in form of files.\ - This script contains only the programmed code.\ - It is needed when the data needs to be varied over the test run.\ - If the data undergoes any change the script need not be modified.\ - The expected data is stored in the data files that have test data.\ \ 5. **Keyword driven testing**\ - It is the control to check and execute operations in maintained with external data files.\ - The external data file will test data and the operations/sequence of the test is planned in and extra library which needs to interpret this data in addition to the conventional script.\ - It is an extension of data driven testing. ------------------------- ------------------------------------------------------------------------------------------------------ **Week 10** Scripting Language **Lesson Title** **Client-Side Scripting** **Learning Outcome(s)** Discuss interactive web-based application that uses client-side script to pass data from a web page. ------------------------- ------------------------------------------------------------------------------------------------------ **Scripting Language** a series of commands that are able to be executed without the need for compiling. **Interpreter** is a computer program that directly executes instructions written in a programming or scripting language, without requiring them previously to have been compiled into a machine language program.  **Compiler** is a computer program that translates computer code written in one programming language (the source language) into another language (the target language). **GCC** was originally written as the compiler for the [GNU operating system](http://www.gnu.org/gnu/thegnuproject.html).  ***Client-side scripting*** Performed to generate a code that can run on the client end (browser) without needing the server side processing Basically, these types of scripts are placed inside an HTML document. The client-side scripting can be used to examine the user's form for the errors before submitting it and for changing the content according to the user input. As I mentioned before, the web requires three elements for its functioning which are, client, database and server. The effective client-side scripting can significantly reduce the server load. It is designed to run as a scripting language utilizing a web browser as a host program. For example, when a user makes a request via browser for a webpage to the server, it just sent the HTML and CSS as plain text, and the browser interprets and renders the web content in the client end. Client-side scripting languages: **HTML**: It is the fundamental building blocks of web programming which provides the frame to the website. It describes the arrangement of the content. **CSS**: CSS provides the way to design the graphic elements which help in making the appearance of the web application more attractive. **JavaScript**: It is also a client-side scripting language which essentially devised for the specific purpose, but currently there are various JavaScript frameworks used as server-side scripting technology. ***JAVASCRIPT*** Earlier **JavaScript** was named **LiveScript**, but later Netscape changed its name to JavaScript because its origin was from Java which was very popular at that time. JavaScript released its first look for Netscape 2.0 in 1995 under the name \"LiveScript\". **Where is JS being used?** - JavaScript can interact with HTML DOM elements and dynamically control the webpage. - You can perform client-side validation using Javascript. - Using JavaScript, you can create drop-down menus, pop-up windows and dialog boxes. - JavaScript can be used to load asynchronous data without refreshing the webpage. - JavaScript can be used in game development. **Advantage of javaScript** - Speed: Being a client-side scripting language, JavaScript is very fast because all its code functions run immediately on the client machine instead of contacting the server and waiting for a response. - Simplicity: JavaScript is relatively easy to learn and code. - Versatility: JavaScript works well with other languages and also used in a wide variety of applications. - Server Load: Being on the client-side, it reduces the requirement on the website server. What does the script Mean? A script is a set of instructions given in the form of codes. The instructions are designed either for the Web browser (client-side scripting) or the server (server-side scripting). Scripts provide change to a Web page. What does client-side scripting mean? The client is the structure or system on which the Web browser runs. JavaScript is the primary client-side scripting language for the Web. Client-side scripts get interpreted by the browser. The server is where the Web page and other content reside. The server sends pages to the user/client on request. This single programming language facilitates this combine handling of client-server. ***What can JavaScript do?*** *JavaScript can change HTML content* *JavaScript can change HTML attributes* ![](media/image9.png) JavaScript can change CSS Style JavaScript can hide HTML elements ![](media/image11.png) **JavaScript Statements** A JavaScript program is a list of statements to be executed by a computer. **JavaScript Numbers** Number can be written with or without decimals. ![](media/image13.png) **JavaScript Variables** In this example, x is defined as a variable. Then, x is assigned the value of 6: **JavaScript Operators** JavaScript uses arithmetic operators to compute values (just like algebra). ![](media/image15.png) **Assigning JavaScript Values** In JavaScript the = operator is used to assign values to variables. **JavaScript is Case Sensitive** Try change lastName to lastname. ![](media/image17.png) ------------------------- ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- **Week 11** **Lesson Title** **Server-Side Scripting** **Learning Outcome(s)** Discuss an interactive web-based application that uses server-side script to process data than can retrieve valid rows of data by connecting PHP to Database (MySQL) using MySQLi Connection method ------------------------- ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- **Server Language** a method of designing websites so that the process or user request is run on the originating server **Interpreter** is a computer program that directly executes instructions written in a programming or scripting language, without requiring them previously to have been compiled into a machine language program.  **ORDER BY** clause is used to sort the result-set in ascending or descending order **UPDATE** statement is used to update existing records in a table ***Server-side scripting*** A method of designing websites so that the process or user request is run on the originating server. Server-side scripts provide an interface to the user and limit access to proprietary data and help keep control of the script source code ***PHP MySQL Database*** MySQL is the most popular database system used with PHP. MySQL is a database system used on the web MySQL is a database system that runs on a server MySQL is ideal for both small and large applications MySQL is very fast, reliable, and easy to use MySQL uses standard SQL MySQL compiles on a number of platforms MySQL is free to download and use MySQL is developed, distributed, and supported by Oracle Corporation **PHP + MySQL Database System** - PHP combined with MySQL are cross-platform (you can develop in Windows and serve on a Unix platform) **Should I Use MySQLi or PDO?** Both MySQLi and PDO have their advantages: PDO will work on 12 different database systems, whereas MySQLi will only work with MySQL databases. So, if you have to switch your project to use another database, PDO makes the process easy. You only have to change the connection string and a few queries. With MySQLi, you will need to rewrite the entire code - queries included. **Open a Connection to MySQL** Before we can access data in the MySQL database, we need to be able to connect to the server: **Create a MySQL Database Using MySQLi** The CREATE DATABASE statement is used to create a database in MySQL. The following examples create a database named \"myDB\": ![](media/image19.png) **Create a MySQL Table Using MySQLi** The CREATE TABLE statement is used to create a table in MySQL. We will create a table named \"MyGuests\", with five columns: \"id\", \"firstname\", \"lastname\", \"email\" and \"reg\_date\": After the data type, you can specify other optional attributes for each column: - NOT NULL - Each row must contain a value for that column, null values are not allowed - DEFAULT value - Set a default value that is added when no other value is passed - UNSIGNED - Used for number types, limits the stored data to positive numbers and zero - AUTO INCREMENT - MySQL automatically increases the value of the field by 1 each time a new record is added - PRIMARY KEY - Used to uniquely identify the rows in a table. The column with PRIMARY KEY setting is often an ID number, and is often used with AUTO\_INCREMENT ![](media/image21.png) **Insert Data Into MySQL Using MySQLi** After a database and a table have been created, we can start adding data in them. Here are some syntax rules to follow: - The SQL query must be quoted in PHP - String values inside the SQL query must be quoted - Numeric values must not be quoted - The word NULL must not be quoted Here are some syntax rules to follow: - The SQL query must be quoted in PHP - String values inside the SQL query must be quoted - Numeric values must not be quoted - The word NULL must not be quoted The INSERT INTO statement is used to add new records to a MySQL table: ![](media/image23.png) **PHP MySQL Select Data** Select Data From a MySQL Database The SELECT statement is used to select data from one or more tables: **PHP MySQL Use The WHERE Clause** Select and Filter Data From a MySQL Database The WHERE clause is used to filter records. The WHERE clause is used to extract only those records that fulfil a specified condition. ![](media/image25.png) **PHP MySQL Use the ORDER BY Clause** The ORDER BY clause is used to sort the result-set in ascending or descending order. The ORDER BY clause sorts the records in ascending order by default. To sort the records in descending order, use the DESC keyword. **PHP MySQL Delete Data** Delete Data From a MySQL Table Using MySQLi The DELETE statement is used to delete records from a table: ![](media/image27.png) **PHP MySQL Update Data** Update Data In a MySQL Table Using MySQLi and The UPDATE statement is used to update existing records in a table:

Use Quizgecko on...
Browser
Browser