object oriented php overview

13
OO PHP Object Oriented PHP

Upload: larry-ball

Post on 10-Feb-2015

1.483 views

Category:

Technology


2 download

DESCRIPTION

 

TRANSCRIPT

Page 1: Object Oriented PHP Overview

OO PHPOO PHPObject Oriented PHP

Page 2: Object Oriented PHP Overview

OO PHPOO PHPObject Oriented PHP

•Text

Advantages over functional programming

Systematic procedure for designing application by extracting nouns and verbs from specifications and using CRC (Classes, Responsibilities, Collaborators) Cards, then formation of a UML diagram.

Much, much easier to maintain and add or change functionality

Elimination of repetitious code - DRY (Don’t repeat yourself)

Enables use of design patterns – super efficient algorithms that have evolved for accomplishing common OOP application functionality

Page 3: Object Oriented PHP Overview

Universal Modeling Language

Universal Modeling Language

Inheritance – “is a”Aggregation – “has a”Dependency – collaborating classesInterface – contract for concrete implementation

(Horstmann, 2010)

Page 4: Object Oriented PHP Overview

Fundamental ConceptsFundamental ConceptsInheritance - extends

override methods

Setting Access Modifiers

public, private, protected

Use getter/setter methods and private instance variables (attributes)

Static Method or Attribute – belongs to the class, not the object instance (e.g., counters)

Scope resolution operator - error if cannot resolve

Paamayim Nekudotayim*

Referencing Parent Class – self:: parent:: works with parent static or instance methods but not parent attributes, as well as $this-> refers to instance

Constructors/Destructors – give a default value __construct($var=0){}

Cloning Objects clone keyword and __clone() method

Comparing Objects == vs. ===

Object Oriented PHP for Beginners http://www.killerphp.com/tutorials/object-oriented-php/

* Error Message in Hebrewpaam = Oneayim = Doublednekudot = Dotayim = Doubled

Page 5: Object Oriented PHP Overview
Page 6: Object Oriented PHP Overview

Cloning vs. Object references

Page 7: Object Oriented PHP Overview

Design PatternsDesign PatternsThe Strategy Pattern defines a family of algorithms, encapsulates each one, and makes them interchangeable (polymorphism). Strategy lets the algorithm vary independently from the clients that use it.

The Template Method pattern allows a programmer to define the skeleton of an algorithm in a superclass and delegate specific steps to a subclass. Subclasses can redefine certain steps of an algorithm without changing the algorithm's structure.

The Iterator Pattern provides a way to access the elements of an aggregate object sequentially without exposing its underlying representation.The Adaptor Pattern changes the interface of one or more classesThe Decorator Pattern attaches additional responsibilities to an object dynamically. Decorators provide a flexible alternative to subclassing.The Singleton Pattern ensures a class only has one instance and provides a global point of access to it.

Page 8: Object Oriented PHP Overview

Project OverviewProject Overview

Photo gallery

Thumbnail view

Full image view

Comments

Pagination

Page 9: Object Oriented PHP Overview

Project OverviewProject OverviewAdministration Back End

Login

Create Admin users

Upload images

Delete Images

Review/Delete Comments

Page 10: Object Oriented PHP Overview

ObjectsObjectsUser

Photograph

Comment

These will also serve as database tables. Usually when you have a database table you have an object for that table.

Database

singleton pattern and allows for adaptor pattern use if database format changes, e.g., from MySQL to Oracle

Session

Additional Requirements

Pagination

Thumbnail generation

Page 11: Object Oriented PHP Overview

UML Diagram

UML Diagram

Page 12: Object Oriented PHP Overview

Helpful LinksHelpful LinksObject Oriented PHP for Beginners http://www.killerphp.com/tutorials/object-oriented-php/

Page 13: Object Oriented PHP Overview

ReferencesReferencesFreeman, Eric., Freeman, Elisabeth, Sierra, K., Bates, B. (2004). Head first design patterns. Sebastpol, CA: O’Reilly Media, Inc.

Horstmann, C. (2010). Big Java 4th edition. (pp. 512-513). United States of America: John Wiley & Sons, Inc.

Koffman, E. (2010). Data structures: abstraction and design using Java. (pp. 685-694). United States of America: John Wiley & Sons, Inc.

Lynda.com. (2009, March 25). PHP with MySQL beyond the basics. Retrieved from http://www.lynda.com/tutorial/653