Top Banner
Date : 02/05/2012 Web Technology Solutions Class: OOP PHP, Design Patterns and CRUD
30

Date : 02/05/2012 Web Technology Solutions Class: OOP PHP, Design Patterns and CRUD.

Jan 02, 2016

Download

Documents

Louise Doyle
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Date : 02/05/2012 Web Technology Solutions Class: OOP PHP, Design Patterns and CRUD.

Date : 02/05/2012

Web Technology SolutionsClass: OOP PHP, Design Patterns and CRUD

Page 2: Date : 02/05/2012 Web Technology Solutions Class: OOP PHP, Design Patterns and CRUD.

Tonight

✤ CRUD Redux

✤ Hands On Functions\Arrays

✤ Objects in PHP

✤ OOP Design Patterns

✤ Lab

Page 3: Date : 02/05/2012 Web Technology Solutions Class: OOP PHP, Design Patterns and CRUD.

Lab Preview

✤ Continue to build a simple CRUD app with the presidents table.

Page 4: Date : 02/05/2012 Web Technology Solutions Class: OOP PHP, Design Patterns and CRUD.

CRUD ReviewCreate, Read, Update and Delete. How To, Tips, Tricks

Page 5: Date : 02/05/2012 Web Technology Solutions Class: OOP PHP, Design Patterns and CRUD.

Array and Function Challenges4 quick challenges to test your programming skills.

Page 6: Date : 02/05/2012 Web Technology Solutions Class: OOP PHP, Design Patterns and CRUD.

Array Challenge #1

$arr = array("name", "age", "race", "job");Search through this array and find the item “race” and return the key of that item.

Page 7: Date : 02/05/2012 Web Technology Solutions Class: OOP PHP, Design Patterns and CRUD.

Array Challenge #2Find only what is different in these two arrays and return those unique elements.$array1 = array(1 => "WA", "CA", "UT", "MT");$array2 = array(2 => "CA", "MT", "UT");

Page 8: Date : 02/05/2012 Web Technology Solutions Class: OOP PHP, Design Patterns and CRUD.

Function Challenge #1Create a custom function that takes two array’s and combines those arrays into one array and return a single array.$array1 = array(1 => "WA", "CA", "UT", "MT");$array2 = array(2 => "VA", "NV", "OR");

Page 9: Date : 02/05/2012 Web Technology Solutions Class: OOP PHP, Design Patterns and CRUD.

Function Challenge #2With the following string, break up each word and put the contents of each word into an array. Then echo out the contents of that array.$string = “Tomato Sausage Cheese Peppers Mushrooms”;

Page 10: Date : 02/05/2012 Web Technology Solutions Class: OOP PHP, Design Patterns and CRUD.

OOP in PHP

✤ Object Oriented Programming

✤ Objects and Classes

✤ PHP4 vs PHP5

✤ Design Patterns

✤ Example

Page 11: Date : 02/05/2012 Web Technology Solutions Class: OOP PHP, Design Patterns and CRUD.

OOP in PHP

✤ Objects are discrete bundles of functions relating a concept (database connections, image creation, managing users)

✤ Objects work together to create applications.

✤ Service multiple projects with a single set of code.

✤ Code is portable, encapsulated, reusable and easier to debug.

Page 12: Date : 02/05/2012 Web Technology Solutions Class: OOP PHP, Design Patterns and CRUD.

OOP Example

Page 13: Date : 02/05/2012 Web Technology Solutions Class: OOP PHP, Design Patterns and CRUD.

OOP Car

✤ Functions of a car

✤ Accelerate, Stop, Steering

✤ How? (implementation)

✤ Gas Pedal, Engine

✤ Breaks

✤ Steering and Wheels

✤ Care how it works? No.

Page 14: Date : 02/05/2012 Web Technology Solutions Class: OOP PHP, Design Patterns and CRUD.

Object Oriented Programming

What is an object:

✤ A “copy” or “instance” of a class.

✤ Objects have properties (color, speed, horsepower, seats)

✤ Objects have methods (accelerate, stop, steering).

Page 15: Date : 02/05/2012 Web Technology Solutions Class: OOP PHP, Design Patterns and CRUD.

Object Oriented Programming

<?php

/*

* File Name: car

* Date: November 18, 2010

* Author: Lincoln Mongillo

* Description: Manages Car

*/

class Car

{

}

?>

Page 16: Date : 02/05/2012 Web Technology Solutions Class: OOP PHP, Design Patterns and CRUD.

Object Oriented Programming

<?php

$myRaceCar = new Car();

$myRaceCar -> accelerate(55);

?>

Page 17: Date : 02/05/2012 Web Technology Solutions Class: OOP PHP, Design Patterns and CRUD.

Object Oriented Programming

Car = a basic blueprint that represents any car.

color

wheels

seats

horsepower

With Car we can “create” other types of speciality cars: dump trucks, sports cars. How? Classes can “inherit” properties and methods from other classes.

Page 18: Date : 02/05/2012 Web Technology Solutions Class: OOP PHP, Design Patterns and CRUD.

Object Oriented Programming

Car

racecar

truck

wheels: 4color: whiteseats: 4horsepower: 8

wheels: 4color: whiteseats: 2horsepower: 200

wheels: 4color: whiteseats: 4horsepower: 200

wheels: 4color: whiteseats: 4horsepower: 200

wheels: 4color: redseats: 8horsepower: 100

Page 19: Date : 02/05/2012 Web Technology Solutions Class: OOP PHP, Design Patterns and CRUD.

Object Oriented Inheritance

<?php

/*

* File Name: RaceCar

* Date: November 18, 2008

* Author: Lincoln Mongillo

* Description: Manages RaceCars

*/

class RaceCar extends Car

{

}

?>

Page 20: Date : 02/05/2012 Web Technology Solutions Class: OOP PHP, Design Patterns and CRUD.

Object Oriented Polymorphism

A Truck vs. Race Car come from car.

Extending a class allows for “Polymorphism” which allows you to perform different tasks based on the context you’re using it in.

Example: stop() between truck vs. racecar is somewhat the same but different because of the nature of the truck (size) and racecar (speed). It might implement the method differently to get the result.

Page 21: Date : 02/05/2012 Web Technology Solutions Class: OOP PHP, Design Patterns and CRUD.

Object Oriented Encapsulation

Don’t need to know how it works (members functions or props)

You just need to know what you can do (available methods - interface)

Page 22: Date : 02/05/2012 Web Technology Solutions Class: OOP PHP, Design Patterns and CRUD.

Object Oriented EncapsulationHow do you know what you can use?

Levels of visibility

• public: means that a class member is visible and usable / modifiable by everyone - default in PHP

• private: means that a class member is only usable / modifiable by the class itself

• protected: means that a class member is only usable / modifiable by the class itself and eventual sub-classes

Page 23: Date : 02/05/2012 Web Technology Solutions Class: OOP PHP, Design Patterns and CRUD.

Class Constructor - PHP4

<?php

class Car

{

public function Car() {

echo "We just created and object!";

}

}

?>

Page 24: Date : 02/05/2012 Web Technology Solutions Class: OOP PHP, Design Patterns and CRUD.

Class Constructor - PHP5

<?php

class Car

{

    function __construct() {  

        echo "We just created and object!";  

    }  

}

?>

Page 25: Date : 02/05/2012 Web Technology Solutions Class: OOP PHP, Design Patterns and CRUD.

Class Constructor - Properties

<?php

class Car

{

private $color;  

private $wheels;  

private $seats;  

    function __construct() {  

$this->color = “OxFFFFF”;

$this->wheels = 4;

    }  

}

?>

Page 26: Date : 02/05/2012 Web Technology Solutions Class: OOP PHP, Design Patterns and CRUD.

Class Constructor - Properties

    function __construct() {  

$this->color = “OxFFFFF”;

$this->wheels = 4;

 

// $this is a reference to the object that is calling it.

$truck = new Car(); // $this = truck.

Page 27: Date : 02/05/2012 Web Technology Solutions Class: OOP PHP, Design Patterns and CRUD.

Object Oriented Programming

Image Example

Database Example

Page 28: Date : 02/05/2012 Web Technology Solutions Class: OOP PHP, Design Patterns and CRUD.

Lab & Next Week

✤ Please send me your Survey in word doc format.

✤ Your personal DB will be updated next week and we will start working on the app.

Page 29: Date : 02/05/2012 Web Technology Solutions Class: OOP PHP, Design Patterns and CRUD.

Lab & Next Week

✤ Homework

✤ Complete Presidents CRUD system

Page 30: Date : 02/05/2012 Web Technology Solutions Class: OOP PHP, Design Patterns and CRUD.

Lab & Next Week

✤ Next week we will

✤ Create Registration system

✤ Create Login w\ Encrypt Password.

✤ Security and Authorization

✤ Reading: Chapter 8

See you Tuesday!