Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> Ocena - Klasy tworzenia planety.
q3trm
post 10.04.2013, 21:51:29
Post #1





Grupa: Zarejestrowani
Postów: 83
Pomógł: 1
Dołączył: 26.02.2013

Ostrzeżenie: (0%)
-----


Cześć.

Na początku zaznaczam, że to moje początki OOP, żeby nie było facepalmxd.gif.


  1. class creatPlanet // klasa konstrukcyjna
  2. {
  3. public $planet;
  4.  
  5. public function __construct(Planet $class)
  6. {
  7. return $this ->planet = $class;
  8. }
  9.  
  10. }
  11.  
  12.  
  13. abstract class FuncPlanet // funkcje planet
  14. {
  15. public function __construct()
  16. {
  17. $this ->nameplanet = get_class($this);
  18. $this ->increase = strlen($this ->nameplanet);
  19. }
  20.  
  21. public function getParamPlanet() //wyświetla wszystkie parametry ustawione przez użytkownika
  22. {
  23. foreach ($this ->parameter as $param => $p)
  24. {
  25. echo '<br />'.$param. ' +' .$p;
  26. }
  27. }
  28. public function getIncrease() //szybkość rozwoju planety
  29. {
  30. return $this ->increase;
  31. }
  32. public function getNamePlanet() //nazwa planety użytkownika
  33. {
  34. return $this ->nameplanet;
  35. }
  36. }
  37.  
  38.  
  39. abstract class Planet extends FuncPlanet // ustawienie początkowych parametrów planety przez użytkownika
  40. {
  41. protected $increase;
  42. protected $nameplanet;
  43. protected $parameter = array();
  44.  
  45.  
  46. function __construct($economic = 0, $military = 0, $explorative = 0)
  47. {
  48. $this ->parameter = array (
  49. 'economic' => $economic,
  50. 'military' => $military,
  51. 'explorative' => $explorative
  52. );
  53. parent::__construct();
  54. }
  55. }
  56.  
  57.  
  58. class Mercury extends Planet {}
  59. class Venus extends Planet {}
  60. class Earth extends Planet {}
  61. class Jupiter extends Planet {}
  62. class Saturn extends Planet {}
  63. class Uranium extends Planet {}
  64. class Neptune extends Planet {}
  65.  


Ten post edytował q3trm 10.04.2013, 21:52:39
Go to the top of the page
+Quote Post

Posty w temacie


Reply to this topicStart new topic
1 Użytkowników czyta ten temat (1 Gości i 0 Anonimowych użytkowników)
0 Zarejestrowanych:

 



RSS Wersja Lo-Fi Aktualny czas: 13.08.2025 - 22:45