Friday 19 August 2022

Design Pattern in PHP

<?php

class Booklibrary {

 private $bookName = '';

 private $bookAuthor = '';

 const BR = '<br/>';

 public function __construct($name = '', $author = '') {

  $this->bookName = $name;

  $this->bookAuthor = $author;

 }

 public function getNameAndAuthor() {

  return $this->bookName . ' - ' . $this->bookAuthor . self::BR;

 }

}

class BooklibraryFactory {

 public static function create($name, $author) {

  return new Booklibrary($name, $author);

 }

}

$bookOne = BooklibraryFactory::create('Shiv Khera', 'You can win');

$bookTwo = BooklibraryFactory::create('Norman Vincent Peale', 'The Power Of Positive Thinking.');


echo $bookOne->getNameAndAuthor();

echo $bookTwo->getNameAndAuthor();

No comments:

Post a Comment

Parenting tips to inculcate learning habits in your kid

Parenting tips to inculcate learning habits in your kid Tip #1) Children do not learn things, they emitate. So, try to do things by yours...