Jump to content

OOP Inheritance help


c_pattle

Recommended Posts

I have just begun to play around with inheritance when using OOP and have come across a problem. 

 

I have two classes, one called "firstClass" that is the parent class and another that is called "secondClass" that is the child class.  I know that in the child class I can override the methods in the parent class but do you have to override them completely or can you just override certain bits of them? 

 

For example say in I have this method in the firstClass. 

function doSomething() {
    $firstline = "<p>Hello</p>";
    $secondlne = "<p>World</p>";
    $thirdline = "<p>!</p>"
}

 

Then what do I do if I only want to override the second line of this function in the child class "secondClass"?  Is it best to just override everything or are there recommended design patterns for this sort of thing?

 

 

Thanks for any help. 

Link to comment
https://forums.phpfreaks.com/topic/243507-oop-inheritance-help/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.