Advertisement
Guest User

Untitled

a guest
May 20th, 2019
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.73 KB | None | 0 0
  1. <?php
  2.  
  3.  
  4. class Vorlesung
  5. {
  6. // Properties, alle sind private ==> Information Hiding
  7. private $name;
  8. private $nr;
  9. private $dozent;
  10. private $teilnehmer = array();
  11. private $medien;
  12.  
  13. // Setter für $name property
  14. public function setName($name) {
  15. $this->name = $name;
  16. }
  17.  
  18. // Getter für $name property
  19. public function getName() {
  20. return $this->name;
  21. }
  22.  
  23. // Setter für $nr property
  24. public function setNr($nr) {
  25. $this->nr = $nr;
  26. }
  27.  
  28. // Getter für $nr property
  29. public function getNr() {
  30. return $this->nr;
  31. }
  32.  
  33. // Ausgabe der Details einer Instanz / Wird nicht benötigt
  34. /*public function printDetails() {
  35. printf("Die Vorlesung %s (%s) findet heute statt. ", $this->name, $this->nr);
  36. printf("Die Teilnehmer sind: <ul>");
  37. foreach ($this->teilnehmer as $tn) { //nicht notwendig bei unserem Beisspiel
  38. printf("<li>%s</li>", $tn->getNachname);
  39. }
  40. echo "</ul>";
  41. }
  42. */
  43.  
  44. // Setter für einzelneTeilnehmer;
  45. public function addTeilnehmer($tn) {
  46. $this->teilnehmer[] = $tn;
  47. }
  48.  
  49. // Setter für das Hinzufügen von mehreren Teilnehmern gleichzeitig per Array $tn
  50. public function addTeilnehmerArray($tn) {
  51. $this->teilnehmer = array_merge($this->teilnehmer, $tn);
  52. }
  53.  
  54. // Getter für Teilnehmer;
  55. public function getTeilnehmer() {
  56. return $this->teilnehmer;
  57. }
  58.  
  59. // Konstruktor
  60. public function __construct($nr, $name, $dozent) { //getter und setter fehlen für $nr und $dozent weshalb diese später nicht augegeben werden
  61. $this->nr = $nr;
  62. $this->name = $name;
  63. $this->dozent = $dozent;
  64. }
  65. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement