Simple OOP design pattern in PHP

simpleOOP.php :
 


namespace simpleOOP;



/**

*

*/

class Mamalia

{

 private $namaInstance;

 

 //construct digunakan untuk membuat instance

 function __construct()

 {

  $this->namaInstance = 'default';

 }



 public function getName()

 {

  return $this->namaInstance;

 }



 public function setName($namaMamalia)

 {

  $this->namaInstance = $namaMamalia;

 }

}





simpleOOP_run.php :
namespace simpleOOP;
include_once('simpleOOP.php');
$kucing = new Mamalia();
echo "default name: " . $kucing->getName() . "
";
$kucing->setName("mono");
echo "after setName: ". $kucing->getName();

Simple OOP - Google Drive

Comments

Popular posts from this blog

Cara Bikin Blog di blogger.com

Apa itu Boilerplate?

Pengertian Scripting dan Compiled Language