Week 2

January 23-27

Topics of the Week:

  • Object Oriented Programming

We started with an overview of OOP and then dove into an example project of a fake Bank.

Procedural code vs Object Orientation

Procedural is read from top to bottom and uses functions to repeat code:

Func Name (ARGUMENTS…){

  • Does something
  • Return;     }

Objects

Each object is one instance of that “Class” of objects and is one little program within the bigger program.

A “Class” is a definition or blueprint for objects to be created from. It includes all the descriptions (parameters) and actions that object can perform (methods)

Basic parts of an Object:

Name:

Parameters – like arguments

Methods – like functions

 

Parameters or methods can be public, protected, or private. Public variables can be defined or used anywhere within the program (even outside the object). Private can only be used within this object. Protected can be used by all child objects (but we’ll go into this more next week).

Modifiers / accessors – typically public methods used to define or access private variables

When classes are made,  the call a constructor which is basically just a function that does stuff when you create a new object (like define variables, perform validations, etc).

Example of basic class:

class MyClass
{
     public $id;
     protected $pro;
     private $_priv;

     public function My Class ($id)
     {
         $this->id = $id;
     }

     private function validateID ()
     {
         return($this->id > 0);
     }
}

We built a basic Bank application with 3 object classes: Transaction, Account, & Customer. (Click the links to download the php files)

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>