C
Christian Bongiorno
I am currently creating a set of interfaces for a rather large project
we have designed.
Many of the interfaces have the same method names and functionality.
such as:
public void addEventListener(TaskEvent evt); // Extends EventObject
public TaskDetails getDetails(); // task details extends IDetails
These imply a more specific class type but are repetative.
Then it occurred to me, I could create a super interface that contains
generic forms of these methods and have each sub interface extend
them.
example:
public void addEventListener(EventObject evt);
public IDetails getDetails();
The first method requires that implementors use this exact static
type. Such things as
public void addEventListener(TaskEvent evt);
would not satisfy the
public void addEventListener(EventObject evt);
And as for getDetails, although the user could assume a specific
subtype to caste to by the type of implementing class (getDetails() on
a Task object would return a TaskDetails obj -- not gauranteed, but
assumable) and callers would still have to type caste the return type
to get most functionality
So, basically the debate boils down to this:
Do I use generic types in a super interface to reduce copy & paste
(something I despise) or do I apply C&P to a few interface methods and
thus enforce specific subtypes and relieve the caller of casting? I
only intend for there to be maybe 10 interfaces to use these common
methods.
I am leaning toward the second choice.
Thoughts?
Christian
we have designed.
Many of the interfaces have the same method names and functionality.
such as:
public void addEventListener(TaskEvent evt); // Extends EventObject
public TaskDetails getDetails(); // task details extends IDetails
These imply a more specific class type but are repetative.
Then it occurred to me, I could create a super interface that contains
generic forms of these methods and have each sub interface extend
them.
example:
public void addEventListener(EventObject evt);
public IDetails getDetails();
The first method requires that implementors use this exact static
type. Such things as
public void addEventListener(TaskEvent evt);
would not satisfy the
public void addEventListener(EventObject evt);
And as for getDetails, although the user could assume a specific
subtype to caste to by the type of implementing class (getDetails() on
a Task object would return a TaskDetails obj -- not gauranteed, but
assumable) and callers would still have to type caste the return type
to get most functionality
So, basically the debate boils down to this:
Do I use generic types in a super interface to reduce copy & paste
(something I despise) or do I apply C&P to a few interface methods and
thus enforce specific subtypes and relieve the caller of casting? I
only intend for there to be maybe 10 interfaces to use these common
methods.
I am leaning toward the second choice.
Thoughts?
Christian