Hi guys,

I am new in OOP. I know the rules and use of abstract classes but, I just want to know why we should use abctract or what is the purpose of it, rather than using normal classes while we can accomplish same thing in both ways?

If i am wrong please let me know. I'll be happy.

Thanks

Abstract classes are nice in that they aren't full implementations of objects but prototypes of them. So take this bad example.... for example: You have want to have Objects and you want all Objects to have an Identify method but each Object will do something different.

abstract class Object
{
  protected $name = 'Object';
  abstract protected function identify();
  protected function __toString()
  {
    return $this->name;
  }
}
class Square extends Object
{
  // PHP Fatal, class Square doesn't implement required method identify
}
class Square extends Object
{
  protected $name = 'Square';
  protected function identify()
  {
    return 'I am a Square';
  }
}
$square = new Square();
echo $square->identify(); // implementation of abstract method
echo $square; // Inherited implementation of Object::__toString