Basic php help ~~~~ Is there a question about inheritance and interfaces ?~~~~~~~ I have a classpersonimplementsispeak {publicfunctionspeak () {echo & quot; people speak & quot ;;}} class, birds classbirdimpl php Basics for help ~~~~
Is there a question about inheritance and interfaces ?~~~~~~~
I have a class person implements ispeak {public function speak () {echo "speaker" ;}} class,
Bird class bird implements ispeak {public function speak () {echo "" ;}} class
Interface ispeak {public function speak ();}
One artist yrPerson extends person {}
Because artists can learn birds and call me now. I want artists to call birds but do not repeat the code public function speak () {echo "";}
Give me a lecture !!!! The manager said that the code repetition rate is too high ~~~~~
------ Solution --------------------
Forget to inherit the person class. just change it.
PHP code
Class yrPerson extends person {// method for adding a speaker... public function show ($ a) {$ func = Factory: func ($ a); return $ func-> speak () ;}}$ person = new yrPerson (); $ person-> speak (); // speak by yourself $ person-> show ('dog'); // name a dog $ person-> show ('bird '); // learn birds // learn more...