Object-Oriented Programming - PowerPoint PPT Presentation

Loading...

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



Loading


The Adobe Flash plugin is needed to view this content

Get the plugin now

View by Category
About This Presentation
Title:

Object-Oriented Programming

Description:

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
Category:

less

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

Title: Object-Oriented Programming


1
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,
    etc.
  • Although the concept dates from the 1950s,
    Simula from 1967 is probably the first language.

2
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.

3
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.

4
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
    class.
  • An object will have user data with attached code
    to work with that data.

5
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 classs methods
    deals with the class properties and no other
    method does.

6
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.

7
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,)

8
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

9
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-gtname
  • public function set_name(new_name)
    this-gtname new_name

10
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.

11
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
  • Its common practice to define class constants in
    upper case.

12
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

13
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.

14
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)

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