Object-Oriented Programming - PowerPoint PPT Presentation


PPT – Object-Oriented Programming PowerPoint presentation | free to download - id: 8083b8-NjgwZ


The Adobe Flash plugin is needed to view this content

Get the plugin now

View by Category
About This Presentation

Object-Oriented Programming


Object-Oriented Programming Object-oriented programming opens the door to cleaner designs, easier maintenance, and greater code reuseability. – PowerPoint PPT presentation

Number of Views:68
Avg rating:3.0/5.0
Slides: 16
Provided by: DonAr155
Learn more at: http://pacsnet.org


Write a Comment
User Comments (0)
Transcript and Presenter's Notes

Title: Object-Oriented Programming

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 OReilly.
  • A different way of coding. Your code wont run
    faster, be more accurate, have prettier output,
  • Although the concept dates from the 1950s,
    Simula from 1967 is probably the first language.

Object-Oriented Programming
  • Smalltalk from 1972 was the first OOP language in
    widespread use.
  • In the mid 1990s, 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.

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 wont touch anothers data.

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 elses code library.
  • A class is a template for building objects.
  • An object is an instance or occurrence of a
  • An object will have user data with attached code
    to work with that data.

Object-Oriented Programming
  • The data associated with an object are called its
  • 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 classs methods
    deals with the class properties and no other
    method does.

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.

Object-Oriented Programming
  • Well look at some basic syntax.
  • Create an object
  • object new class
  • Access a property
  • object-gtpropertyname
  • Access a method
  • object-gtmethodname(arg,)

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

Object-Oriented Programming
  • Within a method, the this variable is a
    reference to the object on which the method was
  • Declaring a method
  • class Person
  • public name // optional but good practice
  • public function get_name() return
  • public function set_name(new_name)
    this-gtname new_name

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.

Object-Oriented Programming
  • Like global constants assigned with the define()
    function, you can assign constants within a
  • class PaymentMethod
  • Const TYPE_CASH 1
  • Its common practice to define class constants in
    upper case.

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

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.

Object-Oriented Programming
  • Advanced Introspection allows examining an
    objects characteristics (for debugging).
  • class_exists(classname)
  • get_declared_classes()
  • get_class_methods(classname)
  • get_class_vars(classname)

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
  • Now lets look at some concrete examples.
About PowerShow.com