Announcements | Last Post | |
---|---|---|
SoC Curricula | 09/30/2017 01:08PM | |
Demarcation or scoping of examinations and assessment | 02/13/2017 07:59AM | |
School of Computing Short Learning Programmes | 11/24/2014 08:37AM | |
Unisa contact information | 07/28/2011 01:28PM |
Re: OOP August 11, 2013 09:56AM |
Registered: 11 years ago Posts: 73 Rating: 0 |
Language: PHP# I am going to create/define a Person class bellow class Person{ public $isAlive = true; public $firstname; public $lastname; public $designation; public $school; #if all your objects are from the same school then you might as well inniate the school property i.e public $school = ';UNISA';.... public $age; #Bellow is a method for innitiating properties to my person class.. public function __construct($firstname, $lastname, $designation, $school, $age){ $this->firstname = $firstname; $this->lastname = $lastname; $this->designation = $designation; $this->school = $school; $this->age = $age; } #The following method(function) is the interesting part of this code.. public function greet(){ return "Hi my name is ".$this->firstname." I am a proud ".$this->designation." at ".$this->school."<br/>"; } #The person class ends here!!! bellow I';ll make use of the class.. # Ok now that I have created my class, let me create two objects to make use of the class, observe.. $student = new Person(';Sipho';, ';Mkhwanazi';, ';Student';, ';UNISA';, 12345); $teacher = new Person(';Some';, ';Body';, ';Professor';, ';UNISA';, 12345); #Ok two objects have been created now lets do something with them using our greet() method/function located in the class echo $teacher->greet(); echo $student->greet(); #We could even do something more interesting with these objects i.e if object status is alive or firstname and lastname properties/variables are innitiated echo greet() as follows if($teacher->isAlive || $teacher->firstname && $teacher->lastname){ echo $teacher->greet(); } else { echo "Object not innitiated"; } }
Re: OOP August 13, 2013 01:38PM |
Registered: 10 years ago Posts: 14 Rating: 0 |
Re: OOP August 16, 2013 11:16AM |
Registered: 10 years ago Posts: 14 Rating: 0 |
Re: OOP November 12, 2013 12:39PM |
Registered: 11 years ago Posts: 73 Rating: 0 |
Re: OOP November 14, 2013 10:17AM |
Registered: 11 years ago Posts: 123 Rating: 0 |
Re: OOP November 14, 2013 03:39PM |
Registered: 11 years ago Posts: 73 Rating: 0 |
Re: OOP November 14, 2013 11:01PM |
Registered: 11 years ago Posts: 123 Rating: 0 |
Re: OOP November 29, 2013 09:45AM |
Registered: 11 years ago Posts: 167 Rating: 0 |