Posted By:
John_Senford
Posted On:
Thursday, September 18, 2003 03:26 AM
Summary ======= Define an interface which declares static methods. The essence of what I mean by this is: define a number of classes which contain common static methods. Details ======= What we are trying to achieve here is effectively an interface which garuantees us that the classes of a particular type (with a common parent class/interface) will all contain a specific method to which we have static access. Simple example ============== Here we have two classes that implement the Animal interface ( Dog and Cat ). Each class supplies a static method getType()
More>>
Summary
=======
Define an interface which declares static methods.
The essence of what I mean by this is: define a number of classes which contain common static methods.
Details
=======
What we are trying to achieve here is effectively an interface which garuantees us that the classes of a particular type (with a common parent class/interface) will all contain a specific method to which we have static access.
Simple example
==============
Here we have two classes that implement the
Animal
interface (
Dog
and
Cat
). Each class supplies a static method
getType()
which returns some non-instance-specific information (this method is static because the type is the same for all instances of the given class. E.g. ALL
Dogs
are of type 'Doggy').
interface Animal
{
...
}
class Dog implements Animal
{
public static String
getType
()
{
return "Doggy";
}
...
}
class Cat implements Animal
{
public static String
getType
()
{
return "Kitty";
}
...
}
The problem is: How can we garuantee a client application that all Animals will supply (in some way) this static method.
[In this particular example the methods differ only in the information they return, but the solution should allow the implementation of these methods to differ too].
Thanks for your thoughts.
JohnSenford
[@hotmail.com]
<<Less