|
20-maruza: phpda obyektga yonaltirilgan dasturlash. Mvc texnologiyasi
|
bet | 6/6 | Sana | 30.01.2024 | Hajmi | 20,38 Kb. | | #148601 |
Bog'liq 20-maruza phpda obyektga yo’naltirilgan dasturlash. Mvc texnolo-www.kompy.info
class Author {
private $name;
private $email;
public function __construct($name,$email){
$this->name = $name;
$this->email = $email;
}
public function getName(){
return $this->name;
}
public function getEmail(){
return $this->email;
}
}
class Book {
//using array to allow multiple authors
private $authors = array();
private $price;
private $name;
public function __construct($name,$price){
$this->name = $name;
$this->price = $price;
}
public function setPrice($price){
$this->price = $price;
}
public function getPrice(){
return $this->price;
}
public function getName(){
return $this->name;
}
public function addAuthor($name,$email){
$this->authors[] = new Author($name,$email);
}
public function getAuthors(){
return $this->authors;
}}
$book = new Book('Book Name',10.0);
$book -> addAuthor('Kelly','kelly@brainbell.com');
$book -> addAuthor('Ken','ken@brainbell.com'); /* print book info */
echo $book -> getName();
echo $book -> getPrice(); /* print book's authors info */
$authors = $book -> getAuthors(); //Array of authors
foreach ($authors as $author) {
echo $author -> getName();
echo $author -> getEmail();
}
Aggregation ga misol
class Author {
private $name;
private $email;
public function __construct($name,$email) {
$this->name = $name;
$this->email = $email;
}
public function getName() {
return $this->name;
}
public function getEmail(){
return $this->email;
}
}
class Book {
private $authors;
private $price;
private $name;
public function __construct($name,$price,$author){
$this->name = $name;
$this->price = $price;
$this->author = $author;
}
public function setPrice($price){
$this->price = $price;
}
public function getPrice(){
return $this->price;
}
public function getName(){
return $this->name;
}
public function getAuthor(){
return $this->author;
}
}
$author = new Author(Sarvar',webga kirish',10.0,$author);
echo $book->getName(); //webga kirish
echo $book->getAuthor() -> getName(); //Sarvar
echo $book->getAuthor() -> getEmail(); //sarvar@gmail.com
Server tomon uchun mominlashga erishish lozim. Buning uchun hozirgi kunda ommalashgan webga mollaniladi MVC texnologiyasi MVC (Model View Controller) konsepsiyasini qollab quvvatlanishidir. Foydalanuvchiga zarur marovlarning qanday qurilmadan (shaxsiy kompyuter yoki mobil telefondan) ekanligini farqlashi lozim. Bunda malumotni turli platformalarga mos holda shakllantirib beradi.
http://kompy.info
|
| |