Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
Next revision Both sides next revision
dvprog_14 [2019-09-09 09:26]
Daniel Viström
dvprog_14 [2020-05-18 20:19]
Daniel Viström
Line 1: Line 1:
-====== Genomgång 11 - Objektorienterad programmering ======+====== Genomgång - Objektorienterad programmering ======
  
 Viktgt att du lär dig vad som menas med följande och att du kan skilja dem åt: Viktgt att du lär dig vad som menas med följande och att du kan skilja dem åt:
Line 12: Line 12:
  
 ==== Exempel 1 ==== ==== Exempel 1 ====
- 
 <code php> <code php>
 <?php <?php
- 
-// Klassen kan ligga i samma fil som huvudprogrammet, men försök att lägga det i separat fil som i exempel 2. 
- 
-class Counter{ 
- 
-  private $value; 
-   
-  public function __construct(){ 
-    $this->value = 0; 
-  } 
-   
-  public function klick(){ 
-    $this->value++; 
-  } 
-   
-  public function getValue(){ 
-    return $this->value; 
-  } 
-   
-  public function zero(){ 
-    $this->value = 0; 
-  } 
-} 
- 
- 
-// Här börjar huvudprogrammet. 
- 
 include 'head.php'; include 'head.php';
  
Line 65: Line 37:
 include 'foot.php'; include 'foot.php';
  
 +</code>
 +
 +Klassen **Counter** ligger i en separat fil, **counter.php**. \\ 
 +Klassen kan ligga i samma fil som huvudprogrammet, men försök att lägga det i separat fil.
 +
 +<code php>
 +<?php
 +class Counter{
 +
 +  private $value;
 +  
 +  public function __construct(){
 +    $this->value = 0;
 +  }
 +  
 +  public function klick(){
 +    $this->value++;
 +  }
 +  
 +  public function getValue(){
 +    return $this->value;
 +  }
 +  
 +  public function zero(){
 +    $this->value = 0;
 +  }
 +}
 </code> </code>