curt            Sun Aug  1 23:12:59 2004 EDT

  Modified files:              
    /phpdoc/en/language/oop5    abstract.xml 
  Log:
  Clarify what an abstract class can and cannot do, with example.
  
  
http://cvs.php.net/diff.php/phpdoc/en/language/oop5/abstract.xml?r1=1.2&r2=1.3&ty=u
Index: phpdoc/en/language/oop5/abstract.xml
diff -u phpdoc/en/language/oop5/abstract.xml:1.2 
phpdoc/en/language/oop5/abstract.xml:1.3
--- phpdoc/en/language/oop5/abstract.xml:1.2    Thu Jul 15 07:19:55 2004
+++ phpdoc/en/language/oop5/abstract.xml        Sun Aug  1 23:12:59 2004
@@ -1,13 +1,14 @@
 <?xml version="1.0" encoding="iso-8859-1"?>
-<!-- $Revision: 1.2 $ -->
+<!-- $Revision: 1.3 $ -->
  <sect1 id="language.oop5.abstract">
   <title>Object Abstraction</title>
 
   <para>
-   PHP 5 introduces abstract classes and methods. An abstract
-   method only declares the method's signature and does not provide an
-   implementation. A class that contains abstract methods needs to be declared
-   abstract.
+   PHP 5 introduces abstract classes and methods. It is not allowed to create
+   an instance of a class that has been defined as abstract.  Any class that
+   contains at least one abstract method must also be abstract.  Methods
+   defined as abstract simply declare the method's signature they cannot
+   define the implementation.
   </para>
 
   <example>
@@ -15,26 +16,48 @@
     <programlisting role="php">
 <![CDATA[
 <?php
+
 abstract class AbstractClass {
-   abstract public function test();
+
+   /* Force Extending class to define this method */
+   abstract protected function getValue();
+
+   /* Common method */
+   public function print() {
+     print $this->getValue();
+   }
+
 }
 
-class ImplementedClass extends AbstractClass {
-   public function test() {
-       echo "ImplementedClass::test() called.\n";
+class ConcreteClass1 extends AbstractClass {
+
+   protected function getValue() {
+     return "ConcreteClass1";
    }
+
 }
 
-$o = new ImplementedClass;
-$o->test();
+class ConcreteClass2 extends AbstractClass {
+
+   protected function getValue() {
+     return "ConcreteClass2";
+   }
+
+}
+
+$class1 = new ConcreteClass1;
+$class1->print();
+
+$class2 = new ConcreteClass2;
+$class2->print();
 ?> 
 ]]>
    </programlisting>
   </example>
 
    <para>
-    Abstract classes cannot be instantiated. Old code that has no user-defined
-    classes or functions named 'abstract' should run without modifications.
+    Old code that has no user-defined classes or functions named
+    'abstract' should run without modifications.
    </para>
 
  </sect1>


Reply via email to