Welcome Guest, Not a member yet? Register   Sign In
Applying Inheritance
#4

[eluser]chobo[/eluser]
In an abstract class you can have a mix of abstract methods and non-abstract methods; I think this goes for properties as well. An interface is something that can only contain abstract methods and properties, but an abstract class can have a mix. If you have child classes that can build off an implementation of a base class (parent class) then you can override the method in the child classes and add to it, by calling the original.

Ex


Code:
// Parent class

protected function testOutput()
{
   $test = "This is from the parent class, and pretty much every child class uses this text";
   return $test;
}


Code:
// Child Class

//override function from parent
protected function testOutput()
{
  $test = parent::testOutput();
  $test .= $test . "Some other text specific to this child class";
  return $test;
}


Sometimes when you put implementations in parent classes down the road they change. It's hard to design a "perfect" system and it's best to just experiment with different techniques, and you'll pick it up. I'm still in that stage as well Smile

* When you declare a function as abstract it has to be implemented in the inheriting classes and will give you an error if you try and define an implementation where you declared the function as abstract.


Messages In This Thread
Applying Inheritance - by El Forum - 08-07-2007, 07:09 PM
Applying Inheritance - by El Forum - 08-07-2007, 08:23 PM
Applying Inheritance - by El Forum - 08-08-2007, 11:18 AM
Applying Inheritance - by El Forum - 08-08-2007, 06:37 PM



Theme © iAndrew 2016 - Forum software by © MyBB