Classes & Objects There are two main programming paradigms: Procedural Object-Oriented Up to now, everything we have done has been procedural.

Slides:



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

Copyright © 2012 Pearson Education, Inc. Chapter 13: Introduction to Classes.
Written by: Dr. JJ Shepherd
OOP - Object Oriented Programming Object Oriented Programming is an approach to programming that was developed to make large programs easier to manage.
Objectives Introduction to Inheritance and Composition (Subclasses and SuperClasses) Overriding (and extending), and inheriting methods and constructors.
CSE 115/503 Introduction to Computer Science for Majors I1 Example Dog fido = new Dog(new Collar()); Dog rover = new Dog(new Collar()); rover.setCollar(fido.getCollar());
Object-Oriented PHP (1)
OOP in Java Nelson Padua-Perez Chau-Wen Tseng Department of Computer Science University of Maryland, College Park.
Evan Korth New York University Computer Science I Classes and Objects Professor: Evan Korth New York University.
Classes, Encapsulation, Methods and Constructors
OOP in Java Fawzi Emad Chau-Wen Tseng Department of Computer Science University of Maryland, College Park.
OOP and Graphics. Object Oriented Programming The ‘classic’ point of view of a programmer was that the program instructions were the active part, the.
PHP Workshop ‹#› PHP Classes and Object Orientation.
Introduction to Object Oriented Programming. Object Oriented Programming Technique used to develop programs revolving around the real world entities In.
Programming in Java Unit 2. Class and variable declaration A class is best thought of as a template from which objects are created. You can create many.
Specialization and Inheritance Chapter 8. 8 Specialization Specialized classes inherit the properties and methods of the parent or base class. A dog is.
Object Oriented Programming in PHP. Topics Quick OOP Review Classes Magic Methods Static Methods Inheritance Exceptions Interfaces Operators Type Hinting.
ClassesPHPMay-2007 : [‹#›] PHP Classes and Object Orientation.
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.
COMP An Introduction to Computer Programming : University of the West Indies COMP6015 An Introduction to Computer Programming Lecture 07.
CSC 142 Computer Science II Zhen Jiang West Chester University
2010/11 : [1]Building Web Applications using MySQL and PHP (W1)OO PHP PHP Classes and Object Orientation.
Overview The Basics – Python classes and objects Procedural vs OO Programming Entity modelling Operations / methods Program flow OOP Concepts and user-defined.
Introduction to Java Chapter 7 - Classes & Object-oriented Programming1 Chapter 7 Classes and Object-Oriented Programming.
Classes: user-defined types. Organizing method with a class A class is used to organize methods * Methods that compute Mathematical functions * The Scanner.
1 OOP - An Introduction ISQS 6337 John R. Durrett.
Department of Computer Science Data Structures Using C++ 2E Chapter 2 Object-Oriented Design (OOD) and C++  Learn about inheritance  Learn about derived.
CITA 342 Section 1 Object Oriented Programming (OOP)
Basic Concepts of OOP.  Object-Oriented Programming (OOP) is a type of programming added to php5 that makes building complex, modular and reusable web.
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.
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.
CSCI 171 Presentation 15 Introduction to Object–Oriented Programming (OOP) in C++
OOP Basics Classes & Methods (c) IDMS/SQL News
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.
CPS120: Introduction to Computer Science Lecture 16A Object-Oriented Concepts.
Seventh step for Learning C++ Programming CLASS Declaration Public & Private Constructor & Destructor This pointer Inheritance.
Geoff Holmes and Bernhard Pfahringer COMP206-08S General Programming 2.
Computer Programming II Lecture 5. Introduction to Object Oriented Programming (OOP) - There are two common programming methods : procedural programming.
Object-oriented programming (OOP) is a programming paradigm using "objects" – data structures consisting of data fields and methods together with their.
Chapter 2 Objects and Classes
CMSC201 Computer Science I for Majors Lecture 25 – Classes
Introduction to Object-oriented Programming
Written by: Dr. JJ Shepherd
OOP - Object Oriented Programming
Section 2.1: Programming paradigms
Objects as a programming concept
Classes C++ representation of an object
Lesson Objectives Aims Key Words
Understand the Fundamentals of Classes
Objects as a programming concept
Microsoft Visual Basic 2005: Reloaded Second Edition
PHP Classes and Objects
Road Map Introduction to object oriented programming. Classes
Section 2.1: Programming paradigms
CSC 143 Inheritance.
PHP Classes and Object Orientation
Scope, Visibility, and Lifetime
Object-Oriented Programming
Object-Oriented Programming
An Introduction to Object Orientated Programming
Object-Oriented Programming in PHP
Tonga Institute of Higher Education
CPS120: Introduction to Computer Science
C++ Programming ㅎㅎ String OOP Class Constructor & Destructor.
Object-Oriented Programming
Introduction to Object-Oriented Programming
Object-Oriented PHP (1)
CPS120: Introduction to Computer Science
Classes and Objects Imran Rashid CTO at ManiWeber Technologies.
Types of Computer Languages
Presentation transcript:

Classes & Objects There are two main programming paradigms: Procedural Object-Oriented Up to now, everything we have done has been procedural.

Procedural Programming A list of instructions to carry out step-by-step Programs execute from the top down, line by line Programs can rely heavily on functions & other procedures (conditionals, loops)

You should have a good understanding of: variables operators conditionals (if statements) loops functions

Object-Oriented Programming OOP - all computations are based on objects Objects are instances of Classes For example, a dog named Rover is an object of the dog class A class is a blueprint or template for making objects

Example Person Class class Person { private $first; private $last; private $age; } Class with 3 properties (variables) private scope of property – only visible in this class

Class Scope 3 identifiers for class properties (variables) and methods (functions) public – visible outside the class protected - visible to any inherited class private – visible only inside that class

Magic Constructor Method class Person { private $first; private $last; private $age; public function __construct($first, $last, $age) { $this->first = $first; $this->last = $last; $this->age = $age; }

new Object $obj = new Person(); Automatically calls magic constructor method public function __construct() (notice double underscore)

public function __construct($first, $last, $age) { $this->first = $first; $this->last = $last; $this->age = $age; } Special variable $this refers to current object Object operator -> points to class properties & methods Class property references ->age do not use $

Class with New Object class Person { private $first; private $last; private $age; public function __construct($first, $last, $age) { $this->first = $first; $this->last = $last; $this->age = $age; } $obj = new Person($first, $last, $age);

Inheritance Classes may inherit from other classes class Mammal { protected $vertebra; } class Tiger extends Mammal { protected $stripes; public function __construct($vertebra, $stripes) { Mammal::__construct($vertebra); $this -> stripes = $stripes;

:: Scope Resolution Operator Use the scope resolution operator :: to access properties and methods outside the class. public function __construct($vertebra, $stripes) { Mammal::__construct($vertebra);