classes, instances & objects in ZE2

From: Date: Fri, 05 Apr 2002 15:51:59 +0000
Subject: classes, instances & objects in ZE2
References: 1 2 3  Groups: php.dev 
Request: Send a blank email to php-dev+get-82135@lists.php.net to get a copy of this message
Since there is a lot of discussion going on, i had some thoughts. Clearing some terms before: class = template for objects/instances a class holds a list of methods and knows about its parents a class can have static members/methods which can be used without creating an object/instance interface = a collection of methods and members that must be implemnted in a class/object (for example: java uses this to emulate missing multiple inheritance) most languages do not allow code in an interface. for me i like the idea of having static members/methods in interfaces and the dynamic part can be done by using properties -> leads to operator $obj->implements('interface-name') member = a variable bound to an instance/object (like a record member) instance = instance of a class with pointer to method table of class and memory for members (non static class members) for those who do not like pointers: name it class identifier and supply a hashtable to find the class. object = instance with private method table that can differ from the method table of the class it was made of (if made from class) in other words an object can modify/override methods without changing any class if so it is no longer boundable to any class property = a pseudo member realised by a getter and a setter method and now some questions: -> we have no interfaces (as far as i know) -> we have classes and instances not objects (our instances cannot change methods, can they? but they can add members) -> we have private, what about final, public, protected and abstract (can we remove/hide a method from an object)? -> do we allow to reduce visability (replace protected by private as long as we don't have it): class A {
    public function f()..
} class B extends A {
    protected function f()...
} and some more: multiple inheritance = class A extends B, C the problem is that inheritance graph now is no longer a tree -> MANY PROBLEMS current docu does not allow A:B:X instead it is allways 'A:B':X therfore you cannot access any X in C if B also has X (or does what is said about : do apply only for namespaces -> then its confusing!) i would appreciate having interfaces with code! class A {
    function f(string $s) {
      echo "$s\n";
    }
    function f(string $s1, string $s2, string $s3='') {
      f($s1.$s2.$s3);
    }
    function f(array $a) {
      foreach($a as $s) f($s);
    }
} class B extends A {
    function f(array $a) {
      foreach($a as $idx=>$s) f($idx, ':', $s);
    }
} A.f(string) -> executed A.f(string, string, string) calls A.f(string)... A.f(string, string) uses A.f(string, string, string)... A.f(array) calls A.f(string)... B.f(string) calls A.f(string)... B.f(string, string, string) calls A.f(string, string, string)... B.f(string, string) uses B.f(string, string, string)... B.f(array) calls A.f(string, string, string)... same using interfaces: interface L {
    abstract f(string $s);
} interface S { // interface S implemts L should work, too
    f(string $s) {
      echo "$s\n";
    }
    function f(string $s1, string $s2, string $s3='') {
      f($s1.$s2.$s3);
    }
    f(array $a) {
      foreach($a as $s) f($s);
    }
} interface T extends S {
    f(array $a) {
      foreach($a as $idx=>$s) f($idx, ':', $s);
    }
} class A implements S,L { }
  class B extends A implements T {    // implements L because A implements L
} A.f(string) calls S.f(string) -> executed (1) A.f(string, string, string) calls S.f(string,string,string) calls A.f(string) A.f(string, string) uses A.f(string, string, string) (1) A.f(array) calls S.f(array) calls A.f(string)... B.f(string) calls A.f(string) B.f(string, string, string) calls A.f(string, string, string) B.f(string, string) uses B.f(string, string, string) (1) B.f(array) calls T.f(array) calls B.f(string, string, string) so i used class info prior to interface info (runtime) when interface code is done at compile time the result differs in <*>: (2) A.f(string,string,string) calls S.f(string,string,string) calls <*>S.f(string) -> executed (2) A.f(array) calls S.f(array) <*>calls S.f(string) -> executed (2) B.f(array) calls T.f(array) calls <*>S.f(string,string,string) calls S.f(string) -> executes that leads to above code doing (2) and the following code using *needs* performing (1): interface S {
    f(string $s) {
      echo "$s\n";
    }
} interface S2 needs S {
    function f(string $s1, string $s2, string $s3='') {
      f($s1.$s2.$s3);
    }
} interface S3 needs S {
    f(array $a) {
      foreach($a as $s) f($s);
    }
} interface T extends S3 {
    f(array $a) {
      foreach($a as $idx=>$s) f($idx, ':', $s);
    }
} class A implements S,S2,S3 { } class B extends A implements T { } parametric inheritance = class A(type-param) ... mostly resolved by precompilers to full class-sourcecode i think we do not need this BUT we will have loose-types in ZE2 so it would make sence to have it.... BUT Then we should also have methods with same name but different parameter signature message-handlers? marcus

« previous php.dev (#82135) next »