Home > Back-end >  Want to polymorphism, and think about the problems of static
Want to polymorphism, and think about the problems of static

Time:04-13

Polymorphism is for upper more abstract, easy extension, static is convenient to call, but in the Java static method is generally not polymorphic,
I do it, to define abstract classes and abstract method (polymorphism), instantiation, the object is assigned to the abstract class a static attributes (same type), such as call current
Then in this abstract class defines a static method, using the current static attributes, is equivalent to adopt the way of static call, call an instance method,
What are the disadvantages of doing so?
Code like below under
 
Public abstract class Database {
Public static Database current;

Public abstract void create2 ();//abstract method, which can be polymorphic

Public static void the create () {
The current create2 ();
}
}


Call it the Database directly. The create () is ok, but such use is that generally only need only one instance of utility class,
  • Related