neo Posted September 28, 2005 Report Share Posted September 28, 2005 Vai shajaa gadiijumaa ir jeega lietot OOP? klases.php <? class database{ var $db_HOST = "localhost"; var $db_USER = "logins"; var $db_PASS = "parole"; var $datu_baze = "produkti"; var $kluda = "Nevar pieslegties"; var $dbc ; function database() { $this->connect_db(); } function connect_db() { $this->dbc = mysql_connect($this->db_HOST,$this->db_USER,$this->db_PASS); $m = mysql_select_db($this->datu_baze,$this->dbc); return($dbc); } function query($sql) { if ($result = mysql_query($sql,$this->dbc)) { return $result; } } function to_array($result) { $row = mysql_fetch_array($result); return $row; } } ?> index.php <? include("klases.php"); $dat_baz = new database; $dat_baz->database(); $result= $dat_baz->query("SELECT * FROM darzeni"); while ($row = $dat_baz ->to_array($result)) { echo $row[burkani]; } ?> Link to comment Share on other sites More sharing options...
Delfins Posted September 28, 2005 Report Share Posted September 28, 2005 Būs, ja 1.) paramteru imports (attieciģii 2. punkts + konstruktors) 2.) extendēšana - tipa varēs jūzāt anydb (pg,mysql,ora) 3.) error handlings kaut kāds 4.) sql log Link to comment Share on other sites More sharing options...
Analgiins Posted September 28, 2005 Report Share Posted September 28, 2005 Klases konstruktors (shajaa gadiijumaa metode `database()`) jau tiek izpildiits, kad tu izveido jaunu klases objektu: $db = new database(); taapeec nevajag veelreiz izpildiit to database() metodi. Link to comment Share on other sites More sharing options...
bubu Posted September 28, 2005 Report Share Posted September 28, 2005 Un ieteicams izmantot tikai vienu konekciju - taisīt Singleton'u. Link to comment Share on other sites More sharing options...
Delfins Posted September 28, 2005 Report Share Posted September 28, 2005 (edited) Analgiins, ar konstruktoru es dmaju `tieso` konstruktoru, kas atkariibaa no DBDriverType, uztaisa konkrēto instanci... $db_my40 = new DatabaseConn( $params ); .. function DatabaseConn( $params ){ switch ($params->dbdriver) { case 'mysql40': $db = new Mysql40DatabaseConn($params); break; .... } } class Mysql40DatabaseConn extends DatabaseConn { } .. vot tad ir jēga OOP. a rakstīt klasi, tikai pārgrazējot func nosaukumus.. tas nav pareizs OOP pielietojums Edited September 28, 2005 by Delfins Link to comment Share on other sites More sharing options...
bubu Posted September 28, 2005 Report Share Posted September 28, 2005 Factory patterns. Link to comment Share on other sites More sharing options...
Delfins Posted September 28, 2005 Report Share Posted September 28, 2005 juhu. OOP tika izstrādāts priekš Factory.. jēgas citas nav, ja var aprakstīt tikai ar vienu līmeni... Link to comment Share on other sites More sharing options...
0x13hst Posted October 11, 2005 Report Share Posted October 11, 2005 Vismaz butu pastastijushi jautajuma uzdevejam kas ira Singleton a to varbut vinsh neiebrauca. Un ja varu deret ka vinsh neiebreuca kas ira patterni. Link to comment Share on other sites More sharing options...
bubu Posted October 11, 2005 Report Share Posted October 11, 2005 Un mēs esam vainīgi? Link to comment Share on other sites More sharing options...
Aleksejs Posted October 11, 2005 Report Share Posted October 11, 2005 Thinking in Patterns. Bruce Eckel Link to comment Share on other sites More sharing options...
Paulinjsh Posted October 11, 2005 Report Share Posted October 11, 2005 (edited) Es arī neiebraucu vai pareizāk sakot nebija vēlēšanās meklēt, bet jūtu, ka ir kkas labs :) Paldies par linku :) Edited October 11, 2005 by Paulinjsh Link to comment Share on other sites More sharing options...
AcidRain Posted October 12, 2005 Report Share Posted October 12, 2005 OOP ir jēga lietot, ja: 1. Kods tiks lietots vairākos projektos. 2. Kods (kā, piemēram, konektēšanās uz mysql) tiks izsaukts daudzas reizes. 2. Kodu lietos vēl kāds cits bez tā, kurš to kodējis. Es galveno kārt lietoju OOP, jo tas ir parocīgi, man viss ir klasēs un visu es varu salikt ar tā saucamo ķieģelīšu metodi. Citādi neredzu īpašu OOP pielietojumu, it sevišķi iekš PHP. Link to comment Share on other sites More sharing options...
Recommended Posts