PHP – object oriented programming in web development 2: inheritance Dynamic Internet Technologies.

Slides:



Advertisements
Similar presentations
PHP functions What are Functions? A function structure:
Advertisements

CG0119 Web Database Systems Parsing XML: using SimpleXML & XSLT.
Object Oriented Programming in PHP 5
Teppo Räisänen LIIKE/OAMK 2010
MMDE5011 – INTERACTIVE MEDIA PRACTICE 1 WEEK 1: INTRODUCTION TO HTML5
1 Chapter 6: Extending classes and Inheritance. 2 Basics of Inheritance One of the basic objectives of Inheritance is code reuse If you want to extend.
Magnolia Templating. Header Footer Menu Collection Collection Page Template (JSP) Page Properties Page + TemplateContent.
CS 211 Inheritance AAA.
Inheritance Definition Relationships Member Access Control Data Encapsulation Overloading vs. Overriding Constructors & Destructors.
Chapter 8 Inheritance Part 2. © 2004 Pearson Addison-Wesley. All rights reserved8-2 Outline Creating Subclasses Overriding Methods Class Hierarchies Inheritance.
Inheritance Inheritance Reserved word protected Reserved word super
Topics Recap of the Object Model Inheritance Polymorphism – virtual functions Abstract classes, Pure virtual functions Design issues UML examples Templates.
Object-Oriented PHP (1)
Inheritance. Extending Classes It’s possible to create a class by using another as a starting point  i.e. Start with the original class then add methods,
1 Inheritance Reserved word protected Reserved word super Overriding methods Class Hierarchies Reading for this lecture: L&L 8.1 – 8.5.
Fall 2007ACS-1805 Ron McFadyen1 Programming Concepts Chapter 4 introduces more advanced OO programming techniques. Construction of a programs usually requires:
Aalborg Media Lab 23-Jun-15 Inheritance Lecture 10 Chapter 8.
Inheritance. © 2004 Pearson Addison-Wesley. All rights reserved 8-2 Inheritance Inheritance is a fundamental object-oriented design technique used to.
2.5 OOP Principles Part 1 academy.zariba.com 1. Lecture Content 1.Fundamental Principles of OOP 2.Inheritance 3.Abstraction 4.Encapsulation 2.
Object Oriented Software Development
UFCEUS-20-2 : Web Programming Lecture 5 : Object Oriented PHP (1)
Creating Databases for Web Applications Work session Open Source versus Proprietary important topics HW: finish* projects. Look at final quiz guide. Final.
Introduction to Object Oriented Programming. Object Oriented Programming Technique used to develop programs revolving around the real world entities In.
The format is text files, with.htm or.html extension. Hard returns, tabs, and extra spaces are ignored. DO NOT use spaces in file names. File names ARE.
Features of Object Oriented Programming Lec.4. ABSTRACTION AND ENCAPSULATION Computer programs can be very complex, perhaps the most complicated artifact.
Object Oriented Programming Examples: C++, Java Advantages: 1. reusibility of code 2. ability to adapt (extend) previously written code.
CSE 501N Fall ‘09 14: Inheritance 20 October 2009 Nick Leidenfrost.
Mr. Justin “JET” Turner CSCI 3000 – Fall 2015 CRN Section A – TR 9:30-10:45 CRN – Section B – TR 5:30-6:45.
Copyright 2003 Scott/Jones Publishing Standard Version of Starting Out with C++, 4th Edition Chapter 13 Introduction to Classes.
Inheritance Chapter 10 Programs built from objects/instances of classes An O.O. approach – build on earlier work. Use classes in library and ones you have.
Object Oriented Programming Examples: C++, Java Advantages: 1. reusibility of code 2. ability to adapt (extend) previously written code.
2010/11 : [1]Building Web Applications using MySQL and PHP (W1)OO PHP PHP Classes and Object Orientation.
8. Inheritance “Is-a” Relationship. Topics Creating Subclasses Overriding Methods Class Hierarchies Abstract Class Inheritance and GUIs The Timer Class.
Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Java Software Solutions Foundations of Program Design Sixth Edition by Lewis.
Inheritance Objectives: Creating new classes from existing classes The protected modifier Creating class hierarchies Abstract classes Indirect visibility.
Chapter 10: Introduction to Inheritance. Objectives Learn about the concept of inheritance Extend classes Override superclass methods Call constructors.
Coming up: Inheritance
1 Inheritance Reserved word protected Reserved word super Overriding methods Class Hierarchies Reading for this lecture: L&L 9.1 – 9.4.
Copyright © 2010 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Starting Out with Programming Logic & Design Second Edition by Tony Gaddis.
Building a Web Page. Create A New Folder  Right click on the desktop and select New / Folder  Name the folder playpen.
Intermediate PHP (4) Object-Oriented PHP (2). Object-oriented concepts Classes, attributes and operations Class attributes Per-class constants Class method.
Java Software Solutions Lewis and Loftus Chapter 8 Copyright 1997 by John Lewis and William Loftus. All rights reserved. 1 Inheritance -- Introduction.
21. PHP Classes To define a class, use the keyword class followed by the name and a block with the properties and method definitions Properties are declared.
Inheritance in C++ Bryce Boe 2012/08/28 CS32, Summer 2012 B.
Week 5 Extending classes in Java. Extending classes u Using an existing classes as the basis for a new one u Defining only the differences between the.
1 Introduction to HTML. 2 Definitions  W W W – World Wide Web.  HTML – HyperText Markup Language – The Language of Web Pages on the World Wide Web.
Java Programming Fifth Edition Chapter 9 Introduction to Inheritance.
Inheritance Modern object-oriented (OO) programming languages provide 3 capabilities: encapsulation inheritance polymorphism which can improve the design,
Inheritance and Polymorphism
Microsoft Visual Basic 2005: Reloaded Second Edition
Inheritance AKEEL AHMED.
PHP Classes and Objects
Lecture 14 - Abstract Classes
Objects First with Java A Practical Introduction using BlueJ
Understanding Inheritance
Web Systems Development (CSC-215)
Inheritance Basics Programming with Inheritance
Customizing Editable Regions and Building Templates
Lecture 14- Abstract Classes
Two big words Inheritance Polymorphism
Computer Programming with JAVA
Dreamweaver Basics.
Overriding Methods & Class Hierarchies
Chapter 11: Inheritance and Composition
Wordpress test.cs.edinboro.edu.
Inheritance and Polymorphism
Object-Oriented PHP (1)
Classes and Objects Imran Rashid CTO at ManiWeber Technologies.
Object-oriented programming with PHP5
MAKING XSL-PCF PAGES FROM SCRATCH
Presentation transcript:

PHP – object oriented programming in web development 2: inheritance Dynamic Internet Technologies

Content Inheritance Extending parent classes to create more complex and specialised child classes that build on the basic features of the parent Overriding the methods of a parent class

Class inheritance The ability of one class definition (a child) to inherit all of the functionality of another (the parent) and to extend it When a child class inherits from a parent it Has all of the characteristics of its parent – e.g. its methods and properties Can add more complex and specialised features to provide additional or different functionality Can override (redefine) the behaviour of its parent

Inheritance example If we had a vehicle parent class what attributes and methods could it have? What kind of child classes could we have? class vehicle { protected $fuelLevel; protected $noSeats; protected $noWheels; public function getFuelLevel() { echo " Fuel: $this->fuelLevel /n"; } } vehicle caraeroplaneboat

Inheritance – child class ex Creating a child class that inherits all of the functionality of a parent class writing extends means that aeroplane inherits all the functionality of vehicle class vehicle { protected $fuelLevel; protected $noSeats; protected $noWheels; public function getFuelLevel() { // Code to determine and store level echo " Fuel: $this->fuelLevel /n"; } } class aeroplane extends vehicle { } $airbus1 = new aeroplane(); $airbus1->getFuelLevel(); Child object of vehicle

Inheritance – extending a parent class For our aeroplane child class example, what sort of specialised features could it have? The child class can use what it inherits and extend it with its own specialisations class vehicle { protected $fuelLevel; protected $noSeats; protected $noWheels; public function getFuelLevel() { echo " Fuel: $this->fuelLevel /n"; } } class aeroplane extends vehicle { public function lowerLandingGear() { echo " Lowering... /n"; } } $airbus1 = new aeroplane(); $airbus1->getFuelLevel(); $airbus1->lowerLandingGear();

Extending a web page class - example If we had a web page class that served as a basic blueprint for creating web pages with A header, body and footer etc We could create child classes to extend it What specialisations could the child classes have? webPage with menu Different DOCTYPE

Overriding the method of a parent class Child classes can override the methods of their parents Can be required to achieve some different behaviour Provide the child with a method of the same name as in the parent – thus redefining the method class vehicle { protected $fuelLevel; protected $noSeats; protected $noWheels; public function getFuelLevel() { echo " Fuel: $this->fuelLevel /n"; } } class aeroplane extends vehicle { public function getFuelLevel() { // if low send SOS to air // traffic control! } } $airbus1 = new aeroplane(); $airbus1->getFuelLevel(); The child method is called in preference to the parent’s of the same name

Overriding the method of a parent class The overridden function can still call the parent function using… class vehicle { protected $fuelLevel; protected $noSeats; protected $noWheels; public function getFuelLevel() { echo " Fuel: $this->fuelLevel /n"; } } class aeroplane extends vehicle { public function getFuelLevel() { // if low send SOS to air traffic control! parent::getFuelLevel(); } } $airbus1 = new aeroplane(); $airbus1->getFuelLevel();

Overriding - web page class example How could we use overriding in child classes of our webPage class parent? Examples Override the makeHeader method to produce a web page with a different DOCTYPE Override the footer method to create a more complex footer Override the constructor to accept additional parameters like text / image file names etc that the page uses Redefine any method to change functionality

Review We can use inheritance to Extend parent classes to create more complex and specialised child classes that build on the basic features of the parent Overriding the method of a parent class to help achieve some more complex or specialised behaviour. There is a principle in OO that the “local” class member is preferred (very important to OO programming)

References Coggeshall, J. (2005). PHP 5. Sams Publishing. Lerdorf, R. & Tatrow, K. (2005). Programming PHP. O’Reilly Sklar, D. (2004). Learning PHP 5. O’Reilly Valade J. (2004). PHP 5 for Dummies. Wiley. ISBN Welling, L. and Thompson, L. (2005). PHP and MySQL Web Development. Third Edition. Sams Publishing