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 [2017-11-13 01:08]
Daniel Viström
dvprog_14 [2020-05-18 20:17]
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>
 +<?php
 +include 'head.php';
 +
 +$a = new Counter();
 +echo $a->getValue() . '<br>';
  
 +// $a->value--; // Går inte att komma åt eftersom attributet är private.
 +
 +$i = 0;
 +while ($i < 20){
 +  $a->klick();
 +  $i++;
 +}
 +echo $a->getValue() . '<br>';
 +
 +$b = new Counter();
 +$b->klick();
 +echo $b->getValue() . '<br>';
 +
 +$b->zero();
 +echo $b->getValue() . '<br>';
 +
 +include 'foot.php';
 +
 +</code>
 <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.+// Klassen kan ligga i samma fil som huvudprogrammet, men försök att lägga det i separat fil.
  
 class Counter{ class Counter{
Line 38: Line 63:
   }   }
 } }
- 
- 
-// Här börjar huvudprogrammet. 
- 
-include('head.php'); 
- 
-$a = new Counter(); 
-echo $a->getValue() . '<br>'; 
- 
-// $a->value--; // Går inte att komma åt eftersom attributet är private. 
- 
-$i = 0; 
-while ($i < 20){ 
-  $a->klick(); 
-  $i++; 
-} 
-echo $a->getValue() . '<br>'; 
- 
-$b = new Counter(); 
-$b->klick(); 
-echo $b->getValue() . '<br>'; 
- 
-$b->zero(); 
-echo $b->getValue() . '<br>'; 
- 
-include('foot.php'); 
- 
 </code> </code>
  
Line 71: Line 69:
 <code php> <code php>
 <?php <?php
-include('head.php')+include 'head.php'; 
-include('animals.php');+include 'animals.php';
  
  
Line 90: Line 88:
 echo $d1->info();  // Det kan vara bra att fatta vad som händer här... echo $d1->info();  // Det kan vara bra att fatta vad som händer här...
    
-include('foot.php');+include 'foot.php';
  
 </code> </code>