Learning OOP in PHP. What is OOP? OOP stands for Object Oriented Programming. OOP is a programming paradigm wherein you create “objects” to work with.

Slides:



Advertisements
Similar presentations
Understand and appreciate Object Oriented Programming (OOP) Objects are self-contained modules or subroutines that contain data as well as the functions.
Advertisements

By Waqas Over the many years the people have studied software-development approaches to figure out which approaches are quickest, cheapest, most.
OOP Abstraction Classes Class Members: Properties & Methods Instance (object) Encapsulation Interfaces Inheritance Composition Polymorphism Using Inheritance.
Object-Oriented Programming Python. OO Paradigm - Review Three Characteristics of OO Languages –Inheritance It isn’t necessary to build every class from.
Department of Computer Engineering Faculty of Engineering, Prince of Songkla University 1 5 – Abstract Data Types.
OBJECT ORIENTED PROGRAMMING M Taimoor Khan
Classes and Object- Oriented... tMyn1 Classes and Object-Oriented Programming The essence of object-oriented programming is that you write programs in.
Object-Oriented PHP (1)
Inheritance and Class Hierarchies Chapter 3. Chapter 3: Inheritance and Class Hierarchies2 Chapter Objectives To understand inheritance and how it facilitates.
Object Oriented Programming A brief review of what you should know about OOP.
Classes, Encapsulation, Methods and Constructors
Object-oriented Programming Concepts
Data Abstraction and Object- Oriented Programming CS351 – Programming Paradigms.
Chapter 13: Object-Oriented Programming
Inheritance and Polymorphism CS351 – Programming Paradigms.
Like our natural language. Designed to facilitate the expression and communication ideas between people and computer Like our natural language. Designed.
CSCI N341: Client-Side Web Programming Copyright ©2004  Department of Computer & Information Science "Object-Oriented" JavaScript.
OOP (Object Oriented Programming with AS3) Flash ActionScript 3.0 Introduction to Thomas Lövgren, Flash developer Introduction.
C++ Object Oriented 1. Class and Object The main purpose of C++ programming is to add object orientation to the C programming language and classes are.
GENERAL CONCEPTS OF OOPS INTRODUCTION With rapidly changing world and highly competitive and versatile nature of industry, the operations are becoming.
Chapter 8 More Object Concepts
An Object-Oriented Approach to Programming Logic and Design
OBJECT ORIENTED PROGRAMMING CONCEPTS ISC 560. Object-oriented Concepts  Objects – things names with nouns  Classes – classifications (groups) of similar.
Recap (önemli noktaları yinelemek) from last week Paradigm Kay’s Description Intro to Objects Messages / Interconnections Information Hiding Classes Inheritance.
JavaScript, Fourth Edition
CS200 Algorithms and Data StructuresColorado State University Part 4. Advanced Java Topics Instructor: Sangmi Pallickara
Chapter 6 Object-Oriented Java Script JavaScript, Third Edition.
Arranging the border values of methods. import java.awt.*; import java.applet.Applet; public class Applet2 extends Applet { public void paint(Graphics.
OOP IN PHP `Object Oriented Programming in any language is the use of objects to represent functional parts of an application and real life entities. For.
1 Classes and Controls CE-105 Spring 2007 By: Engr. Faisal ur Rehman.
Question of the Day  On a game show you’re given the choice of three doors: Behind one door is a car; behind the others, goats. After you pick a door,
Date : 02/03/2014 Web Technology Solutions Class: OOP PHP, Design Patterns and CRUD.
Programming Paradigms Lecturer Hamza Azeem. What is PP ? Revision of Programming concepts learned in CPLB Learning how to perform “Object-Oriented Programming”
Introduction to Classes and Objects. Real Life When a design engineer needs an electrical motor he doesn’t need to worry about –How a foundry will cast.
Programming with Java © 2002 The McGraw-Hill Companies, Inc. All rights reserved. 1 McGraw-Hill/Irwin Chapter 5 Creating Classes.
Object-Oriented Programming. Objectives Distinguish between object-oriented and procedure-oriented design. Define the terms class and object. Distinguish.
Interfaces Chapter 9. 9 Creating Interfaces An interface is a contract. Every class that implements the interface must provide the interface’s defined.
Method Overriding Remember inheritance: when a child class inherits methods, variables, etc from a parent class. Example: public class Dictionary extends.
Inheritance and Class Hierarchies Chapter 3. Chapter 3: Inheritance and Class Hierarchies2 Chapter Objectives To understand inheritance and how it facilitates.
Inheritance and Class Hierarchies Chapter 3. Chapter Objectives  To understand inheritance and how it facilitates code reuse  To understand how Java.
Basic Concepts of OOP.  Object-Oriented Programming (OOP) is a type of programming added to php5 that makes building complex, modular and reusable web.
 We have created our two separate 'person' objects, we can set their properties using the methods (the setters) we created.  class person {  var $name;
Testing in OO Environment The reasons for testing is not any different for any of the design and implementation methodologies, including OO methodology.
Object Oriented Paradigm OOP’s. Problems with Structured Programming As programs grow ever larger and more complex, even the structured programming approach.
Structure A Data structure is a collection of variable which can be same or different types. You can refer to a structure as a single variable, and to.
Geoff Holmes and Bernhard Pfahringer COMP206-08S General Programming 2.
Object-oriented programming (OOP) is a programming paradigm using "objects" – data structures consisting of data fields and methods together with their.
CE-105 Spring 2007 By: Engr. Faisal ur Rehman
Introduction to Object-oriented Programming
Programming paradigms
Classes C++ representation of an object
Concepts of Object Oriented Programming
JAVA By Waqas.
Web Technology Solutions
Objects as a programming concept
11.1 The Concept of Abstraction
Week 4 Object-Oriented Programming (1): Inheritance
INTRODUCTION TO OBJECT-ORIENTED PROGRAMMING (OOP) & CONCEPTS
PRINCIPALES OF OBJECT ORIENTED PROGRAMMING
MSIS 670 Object-Oriented Software Engineering
Object-Oriented Programming
Object-Oriented Programming
An Introduction to Object Orientated Programming
Object-Oriented Programming
Workshop for Programming And Systems Management Teachers
By Rajanikanth B OOP Concepts By Rajanikanth B
Object-Oriented PHP (1)
Object-Oriented Programming
Object Oriented Design & Analysis
C++ Object Oriented 1.
Presentation transcript:

Learning OOP in PHP

What is OOP? OOP stands for Object Oriented Programming. OOP is a programming paradigm wherein you create “objects” to work with.  These objects can then be tailored to your specific needs, to serve different types of applications while maintaining the same code base.

What is an object? An object is simply a copy or instance of a “class”. A class can be defined as a “black box” from where we create our objects and access its attributes (variables) and methods (functions).

Analogy of Classes You don’t need (and most probably don’t want) to know how the car works when you press the pedals. You just want your car to go back and forth, left and right. And OOP is precisely that. The implementation of “Car” is hidden from us, however we can use its full capacities.

Analogy of Classes You don’t need to know how the methods of a class work (if you didn’t implement it yourself), just what they do. OOP is also useful if you have a large number of objects of the same type in a system: you just have to create the objects and then manipulate them all in the same way, without rewriting any code. Moreover, an object is able to maintain it’s state (variable values and such) throughout the execution of the program.

OOP in PHP PHP provides every paradigm other “true” OOP languages implement (Python and JAVA, for example), like inheritance, polymorphism and encapsulation.

Inheritance The basic idea behind inheritance is that similar objects share common properties. So by creating a “generic” class, we can have a blueprint to build our subsequent classes on. Imagine, if you will, a car’s properties: color, number of wheels, horsepower, number of seats, etc. Having this template we can further specialize our cars by extending this class: creating a racing car that has a “nitro” property, or a truck that has a “trailer” property.

Inheritance The bottom line is: create a more generic class that contains most of the common attributes and you will have much less work defining other objects only slightly different. Instead of rewriting the whole code, you just extend it’s properties, saving a lot of time in the process.

Encapsulation As previously explained, one of the main advantages of using objects is that we don’t need to reveal all of its members (attributes or functions); just the necessary interfaces to work with it. Details not useful to the use of these objects should be hidden from the rest of the objects. This is what is referred to as encapsulation.

Encapsulation Levels of visibility  public: means that a class member is visible and usable / modifiable by everyone  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 NOTE: By default, in PHP, a class member is public unless declared private or protected.

Polymorphism Polymorphism is an OOP characteristic that allows the programmer to assign a different meaning or usage to something in different contexts – specifically, to allow a class member to perform different tasks depending on the context it was used. Imagine you have a Person class and two sub- classes of Person: Japanese and American. Both implement a function named talk(), but with different languages and social context. And while both of them are basically People (as they derive from the class Person), their implementation of the function talk() is very different. So you basically have two objects of the class Person in which the talk() function works differently.

Sample Code <?php Class Car{ var $color = "RED"; /*public function Car(){ echo "We just created and object."; }*/ public function __construct(){ echo "Car object created. "; } public function goForward(){ echo "Car object go forward. "; } public function goBack(){ echo "Car object go back. "; } public function turnRight(){ echo "Car object turn right. "; } public function turnLeft(){ echo "Car object turn left. "; } public function activateHorn(){ echo "Car object activate horn. "; }

Sample Code $mycar = new Car(); $mycar->goForward(); $mycar->goBack(); $mycar->turnRight(); $mycar->turnLeft(); $mycar->activateHorn(); echo "Car object color is ".$mycar->color; echo " "; ?> <?php Class Racecar extends Car{ public function __construct(){ echo "Race Car object created. "; } $myracecar = new Racecar(); $myracecar->goForward(); ?>