Example of a php abstract class to learn how to implement a php abstract class
// Define an abstract class
- Abstract class Staff
- {
- Abstract function hire ();
- Abstract function fire ();
- Abstract function promote ();
- Abstract function demote ();
- }
?>
Example 2: php abstract class
Class Employee {
- Private $ title;
- Private $ lastName;
- Private $ firstName;
- Protected $ salary;
- Private $ ratio = 0;
-
- Public function _ construct ($ title, $ firstName, $ mainName, $ salary ){
- $ This-> title = $ title;
- $ This-> firstName = $ firstName;
- $ This-> lastName = $ mainName;
- $ This-> salary = $ salary;
- }
Public function firstName (){
- Return $ this-> firstName;
- }
Public function getlastName (){
- Return $ this-> lastName;
- }
Public function setRatio ($ num ){
- $ This-> ratio = $ num;
- }
Public function getRatio (){
- Return $ this-> ratio;
- }
-
- Public function getTitle (){
- Return $ this-> title;
- }
Public function getSalary (){
- Return ($ this-> salary-$ this-> ratio );
- }
Public function getFullName (){
- Return "{$ this-> firstName}". "{$ this-> lastName }";
- }
Function getSummaryLine (){
- $ Base = "$ this-> title ($ this-> lastName ,";
- $ Base. = "$ this-> firstName )";
- Return $ base;
- }
- }
// Define an abstract class
- Abstract class EmployeeWriter {
- Abstract static function write (Employee $ shopProduct );
- }
Class TextEmployeeWriter extends EmployeeWriter {
- Static function write (Employee $ shopEmployee ){
- $ Str = "{$ shopEmployee-> getTitle ()}:";
- $ Str. = $ shopEmployee-> getFullName ();
- $ Str. = "({$ shopEmployee-> getSalary ()}) \ n ";
- Print $ str;
- }
- }
$ Employee 1 = new Employee ("A", "A1", "A2", 5.99 );
- TextEmployeeWriter: write ($ interval 1 );
- ?>
|