|
|||||||
|
|
|
![]() |
|
|
Strumenti |
|
|
#1 |
|
Senior Member
Iscritto dal: Nov 2008
Messaggi: 411
|
[PHP] dubbi Design Pattern
Ciao a tutti,
vorrei chiedervi delucidazioni su come sia meglio impostare del codice PHP 5 OOP. Nello specifico: mettiamo di avere un classico sito di e-commerce nel quale avrò diversi utenti con i rispettivi ordini. Partendo da un classe "Utente" qual'è il modo migliore per accedere agli ordini dell'utente "X"? E' corretto creare un metodo, nella classe "Utente", chiamato "getOrdini" che attiva una query sql per recupera gli ordini relativi (come faccio ora), oppure è più corretto creare una classe "Ordine" a cui accedere indirettamente da "Utente"? Es: Codice PHP:
Codice PHP:
Es: Codice PHP:
Grazie in anticipo.
__________________
|
|
|
|
|
|
#2 |
|
Senior Member
Iscritto dal: Nov 2008
Messaggi: 411
|
Up.
__________________
|
|
|
|
|
|
#3 |
|
Junior Member
Iscritto dal: Jan 2011
Messaggi: 1
|
PHP design patterns
hi,all.
I was wondering how we should consider the design patterns. I mean: What are they? Are they simply binaries that help us designing consistent application? Are they so used? Why? Where could i find a list about every design patterns on the web? Or at least the 5-10 mist used design patterns? Do phpbb,wordpress or joomla (that i know pretty well) use a design pattern? If yes, then which? I googled MCV PHP and found about 3 italian articles and read about 5 of the first pages ranked and i didn't understand pretty much nothing. They were conflicting and seemed to me confusing. I did understand that it is ... Fortunatly , I found some popular php design patterns ,which includes decorator pattern, strategy pattern,Singleton pattern,factory pattern listed on the PHPKode.com recently. I decide to list the result as the topic for all you guys and girls.Hopely can help you ! Best regards! |
|
|
|
|
|
#4 |
|
Senior Member
Iscritto dal: Jan 2008
Messaggi: 1056
|
Ovviamente se lavori ad oggetti, Ordine è un'entità che ha propri attributi e metodi quindi sicuramente è un oggetto.
Visto che Utente può avere + ordini, io avrei costruito una classe Ordine con tutti gli attributi di un singolo ordine, quali possono essere ID, data, data spedizione eccc.... e poi nella classe Utente avrei messo un array di Ordine. Nel costruttore l'avrei dichiarato null senza inizializzarlo riprendendo le info dal db (sarebbe inutile, un vero spreco di risorse e di millisecondi (che sul web sono preziosi poi sempre in Utente avrei fatto un bel metodo Ordine getOrdini ($id = null) che ritorna l'array di Ordine dell'utente inizializzando l'array come attributo. |
|
|
|
|
|
#5 | |
|
Senior Member
Iscritto dal: Feb 2003
Città: Stockholm (SE)
Messaggi: 1343
|
Quote:
Yours are really interesting questions and the link you shared seems very interesting as well. Unlucky this is an Italian-based board and, as I'm sure you already know, there are tons of forums out there where English is the official language and your suggestions can be fully appreciated. Anyway, if you have any specific question, please ask the moderators or the management of the board about the possibility to open an English based topic. Thanks. Kralizek |
|
|
|
|
|
| Strumenti | |
|
|
Tutti gli orari sono GMT +1. Ora sono le: 15:06.





















