Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> Dziedziczenie, czy niezależne komponenty?
q3trm
post
Post #1





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

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


Cześć.


Mam dwie klasy, Pierwsza która pobiera wyniki wykonania odrębnych klasa. Druga klasa Pobierającą wyniki pierwszej klasy i zamieniającą je na dane sesyjne.

Moje pytanie, czy zgodne z zasadami OOP byłoby połączenie, a właściwie wykonanie tych operacji w jednej klasie?


  1.  
  2. class ImageParameter // kąt oraz pliki zdjęć
  3. {
  4. protected $angleImage;
  5. protected $fileImage;
  6.  
  7.  
  8. public function downloandParam(OperationDir $operationDir, AngleImage $angleImage )
  9. {
  10. $this ->fileImage = $operationDir ->getArrayDir();
  11. $this ->angleImage = $angleImage ->getAngleImage();
  12. }
  13.  
  14. public function getAngleImage()
  15. {
  16. return $this ->angleImage;
  17. }
  18. public function getFileImage()
  19. {
  20. return $this ->fileImage;
  21. }
  22. }
  23.  
  24.  
  25. class SessionParameter
  26. {
  27. protected $instance;
  28.  
  29. function takeInstance (ImageParameter $imageParameter)
  30. {
  31. $this ->instance = $imageParameter;
  32. }
  33. function sessionAngleImage()
  34. {
  35. return $_SESSION['angleImage'] = $this ->instance ->getAngleImage();
  36. }
  37. function sessionFileImage()
  38. {
  39. return $_SESSION['fileImage'] = $this ->instance ->getFileImage();
  40. }
  41.  
Go to the top of the page
+Quote Post
 
Start new topic
Odpowiedzi
Evinek
post
Post #2





Grupa: Zarejestrowani
Postów: 280
Pomógł: 46
Dołączył: 23.03.2010

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


To moje zdanie, a w OOP nie jestem aż tak dobry.

Jedna klasa powinna być od Sesji.
Druga powinna w konstruktorze dostawać wstrzykniętą klasę sesji. Wtedy operacje zapisu powinny być w klasie Image.
Przykład:
  1. class ImageParameter
  2. {
  3. protected $session;
  4.  
  5. public function __construct(Session $session){
  6. $this->session = $session;
  7. }
  8.  
  9. public function saveToSession(){
  10. $this->session->set('angleImage', $this->getAngleImage());
  11. $this->session->set('fileImage', $this->getFileImage());
  12. return $this;
  13. }
  14.  
  15. }


Najlepiej żebyś ktoś mądrzejszy się wypowiedział, a jak mój tok myślenia będzie dobry to będę szczęśliwy. (IMG:style_emoticons/default/biggrin.gif)
Go to the top of the page
+Quote Post

Posty w temacie


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

 



RSS Aktualny czas: 7.10.2025 - 22:18