Introduction to Object Oriented Design Pattern

```````````````````````

What is design Pattern:


<?php


Introduction to Object Oriented Design Pattern
```````````````````````
What is design Pattern:
This means Programming Paradigm (Approach of Programming) or Methodology
Till Now you would have used piece of code in repeated Manner.

In order to Resolve the DRY Approach (Donot Repeat Yourself)
Hence we introduced concept of Functions.

Type of Approaches
1. monolythic : Code in Repeated Fashion (Repeated Approach)
All Code will be written in single File itself.

No One uses this in industry

2. polylithic: 
   All Code Destributed in Multiple File Approach
   1. Functional Approach
   2. Object Oriented Approach
   3. Design Pattern
         There are Total 23 Design Pattern
         Ex.
         (1). Singleton Pattern
         (2). Observer Pattern
         (3). Adapter Pattern
         (4). Factory Pattern
         (5). Fascade Pattern
         etc...
         
  Functional Approach
  ``````````````````````
  We divide the piece of code into blocks of functions
  
  Disadvantages of Functions Approach
  1. Security (Because function does not private, Public,protected [Access Modifier])
  2. Context : Global or Local Context problem arises with version
  3. Undefined Variable Errors (Donot have Garbage Collector)
  4. Top to Bottom Approach
  
  
  Object Oriented Approach
````````````````````````````````````
It is a Programming Methodology or Programming Paradigm
It is software development Mechanism with Additional Advantages
Like
  1. Security By Using[Access Modifier] like Public, Protected,Private
  2. Context: static or Non static 
        static Object cannot be made
        non static object can be made
           1. localhost
           2. global
               public
               private
               protected
               blank Modifier(default): Note that there is no Keywordd for this.
               
               Ex.
              1. public Modifier
                     functions:
                        public function function_name();
                variables: 
                         public variablename
              
              2. private Modifier
                     functions:
                        private function function_name();
                variables: 
                         private variablename  
            
                3. protected Modifier
                     functions:
                        protected function function_name();
                variables: 
                         protected variablename         
               4. default modifier
                    functions
                        function function_name();
                        default variable
                        var <variable>
                        
                        Context Rules: same as Public
                        
3. Garbage Collector
  if dont Initialise the variable
  it will be by default Null
  
  In Procedural
  $x;
  
  echo $x; // undefined Variable $x;
  
  In Oops
  public $x;
  private $x;
  var $x;
  protected $x;
  
  echo $this->x //Null
  
  Real Time Example
  ``````````````````````
  consider a Model
  
  User_model
  class User_model{
  private $tablename = $db['prefix'].'users';
  }
  
  consider a Model
  
  User_model
  class User_model{
  private $tablename = 'tb1_users';
  }
  
4. Bottom to Top Approach

  if you use procedural Approach
  ``````````````````````
  $x;
  echo $x; // Undefined Index in line no 1
  
  Object Oriented
  
  class Test{
     public $x;              <-------------------|
     echo $this->x;                              |
  }                                              |
                                               To Top   
  //No Output                                    |
  As Soon as we make Object                      |
  $obj = new Test(); //Instantiate  <---Bottom---|
  $obj->x=10;
  
  OOPL: Object Oriented Programming Language
  Any Programming Language which follows OOPS Concept or Patterns are said to be OOPS(s)
  
  Example to Object Oriented Pattern
  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  class Test{
   public $x;  //variable inside class Instance Variable
   public $y;  // variable inside class Instance Variable

  //function inside class = Method   
   public function add($x,$y){
   
       echo $x; // local variable
       echo $y; // local variable
        echo $this->x + $this->y; //instance
   }
  }


Introduction to Object Oriented Design Pattern