PACS – 10/19/131 Object-Oriented Programming “Object-oriented programming opens the door to cleaner designs, easier maintenance, and greater code reuseability.”

Slides:



Advertisements
Similar presentations
Chapter 1 Object-Oriented Concepts. A class consists of variables called fields together with functions called methods that act on those fields.
Advertisements

Chapter 1 OO using C++. Abstract Data Types Before we begin we should know how to accomplish the goal of the program We should know all the input and.
OBJECT ORIENTED PROGRAMMING M Taimoor Khan
Objectives Introduction to Inheritance and Composition (Subclasses and SuperClasses) Overriding (and extending), and inheriting methods and constructors.
OBJECT-ORIENTED PROGRAMMING. What is an “object”? Abstract entity that contains data and actions Attributes (characteristics) and methods (functions)
More about classes and objects Classes in Visual Basic.NET.
Object-Oriented PHP (1)
1 Chapter 7 l Inheritance Basics l Programming with Inheritance l Dynamic Binding and Polymorphism Inheritance.
Advanced Object-Oriented Programming Features
C# Programming: From Problem Analysis to Program Design1 Advanced Object-Oriented Programming Features C# Programming: From Problem Analysis to Program.
More on PHP: Objects and Sessions Autumn 2014 Objects Defining objects Inheritance Sessions and session variables.
ASP.NET Programming with C# and SQL Server First Edition
Like our natural language. Designed to facilitate the expression and communication ideas between people and computer Like our natural language. Designed.
Inheritance using Java
UFCEUS-20-2 : Web Programming Lecture 5 : Object Oriented PHP (1)
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.
Chapter 8 More Object Concepts
Objectives In this chapter, you will:
1 Java Inheritance. 2 Inheritance On the surface, inheritance is a code re-use issue. –we can extend code that is already written in a manageable manner.
OOP with PHP Roman Bednarik
Programming Languages and Paradigms Object-Oriented Programming (Part II)
CSCI-383 Object-Oriented Programming & Design Lecture 13.
Chapter 8. About the Midterm Exam.. Exam on March 12 Monday (Tentatively) Review on March 7 Wednesday Cover from Chapter 6 Grades will be out before spring.
Chapter 6 Object-Oriented Java Script JavaScript, Third Edition.
Java Programming, Second Edition Chapter One Creating Your First Java Program.
Sun Certified Java Programmer, ©2004 Gary Lance, Chapter 5, page 1 Sun Certified Java 1.4 Programmer Chapter 5 Notes Gary Lance
Chapter 6 OOP: Creating Object-Oriented Programs Programming in C#.NET © 2003 by The McGraw-Hill Companies, Inc. All rights reserved.
Web Scripting [PHP] CIS166AE Wednesdays 6:00pm – 9:50pm Rob Loy.
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.
Guided Notes Ch. 9 ADT and Modules Ch. 10 Object-Oriented Programming PHP support for OOP and Assignment 4 Term project proposal C++ and Java Designer.
Java Objects and Classes. Overview n Creating objects that belong to the classes in the standard Java library n Creating your own classes.
1 Chapter 8 – Classes and Object: A Deeper Look Outline 1 Introduction 2 Implementing a Time Abstract Data Type with a Class 3 Class Scope 4 Controlling.
An Object-Oriented Approach to Programming Logic and Design Chapter 3 Using Methods and Parameters.
Topic 1 Object Oriented Programming. 1-2 Objectives To review the concepts and terminology of object-oriented programming To discuss some features of.
1 Programming Paradigms Object Orientated Programming Paradigm (OOP)
Introduction to c++ programming - object oriented programming concepts - Structured Vs OOP. Classes and objects - class definition - Objects - class scope.
1 Chapter Four Creating and Using Classes. 2 Objectives Learn about class concepts How to create a class from which objects can be instantiated Learn.
Programming with Microsoft Visual Basic 2012 Chapter 11: Classes and Objects.
Programming with Java © 2002 The McGraw-Hill Companies, Inc. All rights reserved. 1 McGraw-Hill/Irwin Chapter 5 Creating Classes.
VB Classes ISYS 512/812. Object-Oriented Concepts Abstraction: –To create a model of an object, for the purpose of determining the characteristics (properties)
Lecture 10 Concepts of Programming Languages Arne Kutzner Hanyang University / Seoul Korea.
Inheritance. Inheritance - Introduction Idea behind is to create new classes that are built on existing classes – you reuse the methods and fields and.
Chungbuk HRDI of KCCI PhD Kang,Won-Chan PHP Programming (Object)
Object Oriented Programming
Chapter 10: Introduction to Inheritance. Objectives Learn about the concept of inheritance Extend classes Override superclass methods Call constructors.
 In the java programming language, a keyword is one of 50 reserved words which have a predefined meaning in the language; because of this,
CITA 342 Section 1 Object Oriented Programming (OOP)
Object-Oriented Programming (OOP) What we did was: (Procedural Programming) a logical procedure that takes input data, processes it, and produces output.
Chapter 11: Advanced Inheritance Concepts. Objectives Create and use abstract classes Use dynamic method binding Create arrays of subclass objects Use.
Classes, Interfaces and Packages
Basic Concepts of OOP.  Object-Oriented Programming (OOP) is a type of programming added to php5 that makes building complex, modular and reusable web.
Chapter 10 Developing Object-Oriented PHP. 2 Objectives In this chapter, you will: Study object-oriented programming concepts Use objects in PHP scripts.
Object orientation and Packaging in Java Object Orientation and Packaging Introduction: After completing this chapter, you will be able to identify.
1 C# - Inheritance and Polymorphism. 2 1.Inheritance 2.Implementing Inheritance in C# 3.Constructor calls in Inheritance 4.Protected Access Modifier 5.The.
YG - CS Concept of Encapsulation What is encapsulation? - data and functions/methods are packaged together in the class normally.
 We have created our two separate 'person' objects, we can set their properties using the methods (the setters) we created.  class person {  var $name;
Author: DoanNX Time: 45’.  OOP concepts  OOP in Java.
 First thing we need to do is create two PHP pages:  index.php  class_lib.php  OOP is all about creating modular code, so our object oriented PHP.
An Introduction to Programming with C++ Fifth Edition Chapter 14 Classes and Objects.
CSCI/CMPE 4341 Topic: Programming in Python Chapter 7: Introduction to Object- Oriented Programming in Python – Exercises Xiang Lian The University of.
UNIT-IV WT. Why use classes and objects? PHP is a primarily procedural language small programs are easily written without adding any classes or objects.
Object-oriented programming (OOP) is a programming paradigm using "objects" – data structures consisting of data fields and methods together with their.
Introduction to Object-oriented Programming
PHP Classes and Objects
Abstract Classes.
Web Systems Development (CSC-215)
METHODS AND BEHAVIORS AKEEL AHMED.
Object-Oriented Programming
Object-Oriented PHP (1)
Types of Computer Languages
Presentation transcript:

PACS – 10/19/131 Object-Oriented Programming “Object-oriented programming opens the door to cleaner designs, easier maintenance, and greater code reuseability.” – Opening of Chapter 6, “Programming PHP” from O’Reilly. A different way of coding. Your code won’t run faster, be more accurate, have prettier output, etc. Although the concept dates from the 1950’s, Simula from 1967 is probably the first language.

PACS – 10/19/132 Object-Oriented Programming Smalltalk from 1972 was the first OOP language in widespread use. In the mid 1990’s, OOP formed the basis for C++, Java, C#, VB.NET, Python and others. Other languages have had OOP extensions added: Visual Basic, Fortran, Perl, Cobol, etc. And PHP starting in v4. OOP support was much improved in v5.

PACS – 10/19/133 Object-Oriented Programming Non-OOP is called procedural or modular coding. First code was one big glob. Next came separation of code into functional units using subroutines or functions. OOP further separates the data and code into ‘objects’. This makes it easier to debug because only the associated code works with the data. Objects won’t touch another’s data.

PACS – 10/19/134 Object-Oriented Programming As with anything else new, OOP comes with its own terminology and we need to learn some of these terms before we can write our own code or can use someone else’s code library. A class is a template for building objects. An object is an instance or occurrence of a class. An object will have user data with attached code to work with that data.

PACS – 10/19/135 Object-Oriented Programming The data associated with an object are called its properties. The functions associated with an object are called its methods. When you define a class, you define the names of its properties and give the code for its methods. Encapsulation is the idea that a class’s methods deals with the class properties and no other method does.

PACS – 10/19/136 Object-Oriented Programming Inheritance is a way of defining a new class by extending an existing class with new or changed properties and methods. The original class is called the parent, super, or base class.

PACS – 10/19/137 Object-Oriented Programming We’ll look at some basic syntax. Create an object: $object = new class; Access a property: $object->propertyname Access a method: $object->methodname([arg,…])

PACS – 10/19/138 Object-Oriented Programming Methods act just like functions, so they can take arguments and return a value. You can specify which methods and properties are publicly accessible to provide encapsulation. Declaring a class: class classname [extends baseclass] { [var $propertyname [ = value];] [function methodname(args) { code }] }

PACS – 10/19/139 Object-Oriented Programming Within a method, the $this variable is a reference to the object on which the method was called. Declaring a method: class Person { public $name; // optional but good practice public function get_name(){ return $this->name;} public function set_name($new_name) { $this->name = $new_name;} }

PACS – 10/19/1310 Object-Oriented Programming Advanced – When declaring properties, you can use the following access modifiers instead of var to provide encapsulation: public $data1 [=3]; // global protected $data2 [=4]; // within subclasses private $data3 [=5]; // within class Advanced – You can also define static properties on variables on an object class. No object necessary to reference these.

PACS – 10/19/1311 Object-Oriented Programming Like global constants assigned with the define() function, you can assign constants within a class: class PaymentMethod{ Const TYPE_CREDITCARD = 0; Const TYPE_CASH = 1; } It’s common practice to define class constants in upper case.

PACS – 10/19/1312 Object-Oriented Programming To inherit properties and methods from another class, use the extends keyword: class Person { public $name, $address, $age; } class Employee extends Person { public $position, $salary; }

PACS – 10/19/1313 Object-Oriented Programming If a derived class has a property or method with the same name as in its parent class, the one in the derived class takes precedence. Advanced - Constructor functions are called when an object is instantiated. Advanced – Destructor functions are called when the last reference to an object is removed or the script ends.

PACS – 10/19/1314 Object-Oriented Programming Advanced – Introspection allows examining an object’s characteristics (for debugging). class_exists(classname) get_declared_classes() get_class_methods(classname) get_class_vars(classname)

PACS – 10/19/1315 Object-Oriented Programming Advanced – Serialization allows an object to be converted to a bytestream representation that can be stored in a file. serialize(something) unserialize(something) This is commonly used with sessions to provide persistence. Now let’s look at some concrete examples.