PHP

Object-Oriented Programming

One of the key features of object-oriented programming (OOP) is the ability to create new data types in which the data and the implementation of operations are bound together. You create classes that contain the data representing the properties of a particular item, as well as the set of operations that can be performed on it. In addition, most languages including PHP provide mechanisms to customize and extend your objects so that you can create new variations on the types and share common code within them.

Some Basic Terminology

In object-oriented programming, you write code to define new data types, or classes, to represent abstract items. These classes contain properties that represent the fundamental information needed to describe an item. Along with these properties, I can associate operations, called methods or member functions, which you would normally want to perform on those items.

When you create an instance of a class, you have created an object. Therefore, for the products in Beth's Boating Supplies warehouse, I could define a class called Product. This class would have the properties I saw previously, in addition to two member functions or methods:

Product class:
  Properties:
    - product id
    - product name
    - description
    - price per unit
    - supplier location
  Methods:
    - get number in stock
    - add one to an order

An object instance of this class would be one of these Product classes instantiated with the information for a particular product:

Product instance for a fly-fishing lure:
  Properties:
    - product id -- 334355-XR1
    - product name  Joe's Awesome Winter Lure
    - description -- Joe's lures are amazingly popular with...
    - price per unit -- 19.99
    - supplier location -- local warehouse
  Methods:
    - get number in stock
    - add one to an order


by BrainBellupdated
Advertisement: