Laurent For�t wrote:
----- Original Message -----
From: "Nicolas Delsaux" <[EMAIL PROTECTED]>
To: "Laurent For�t" <[EMAIL PROTECTED]>
Sent: Monday, December 09, 2002 12:00 PM
Subject: Re: Class static VS singleton


Le m�thodes statiques ne fournissent pas d'h�ritage. La cons�quence
imm�diate est qu'il n'est pas possible de red�finir leur comportement, ou
m�me de le sp�cialiser, dans le cas o� une impl�mentation plus sp�cialis�e
(par exemple XML ou DB) peut �tre n�cessaire.

Pas compl�tement il est possible d'�tendre ce genre de classe et on peut
red�finir leur comportement :

public class ClassUsingStatic {
  public static void staticMethod() {
    System.out.println("In ClassUsingStatic.staticMethod()");
  }
}
public class OtherClassUsingStatic extends ClassUsingStatic {
 public static void staticMethod() {
     System.out.println("In OtherClassUsingStatic.staticMethod()");
  }
}

Est possible. Par contre, il est vrai que l'on ne peut pas h�riter du
comportement de la classe m�re :

public class ClassUsingStatic {
  public static void staticMethod() {
    System.out.println("In ClassUsingStatic.staticMethod()");
  }
}
public class OtherClassUsingStatic extends ClassUsingStatic {
 public static void staticMethod() {
    super.staticMethod();
    System.out.println("In OtherClassUsingStatic.staticMethod()");
  }
}

On a effectivement, une erreur de compilation :
OtherClassUsingStatic.java [4:1] non-static variable super cannot be
referenced from a static context
    super.staticMethod();
    ^
1 error
heu, pas bien compris le propos.
On a le droit d'�crire :

public class OtherClassUsingStatic extends ClassUsingStatic {
  public static void staticMethod() {
     ClassUsingStatic .staticMethod();
     System.out.println("In OtherClassUsingStatic.staticMethod()");
   }
 }

En fait, c'est sourtout le polymorphisme qui ne marche pas !!

Remi


Répondre à