tags:

views:

64

answers:

4

Part of a big project I'm working on turned out interesting and potentially useful to others, so I'm trying to pull out a chunk of code and release it as its own project. One of its dependencies on the rest of the codebase is an interface that looks like this:

public interface Body {
  void eval(A value);
}

I figure, rather than reinventing this type, it's probably better to introduce a dependency on some commonly-used library that already has it. I've looked through guava and commons-lang, and I'm surprised I can't find anything like this. Any ideas on where else I could look?

A: 

I think this is a bad idea, but:

extra166y.Ops.Procedure

I'm sure you can find similar things in "functional" libraries (even though procedural is kind of the antonym of functional).

Tom Hawtin - tackline
I appreciate these sentiments in general, but... In some cases, it is entirely reasonable to write Java that is abstract enough to make use of a type like this.
Christopher Martin
+2  A: 

If that is the only thing you want, I wouldn't bother placing a whole dependency for that. I tend to adopt the name from already existing projects though, so that it will be easier for other programmers. For example, for Predicate I did write my own interface but I chose the name that should be familiar to Guava users.

Dependencies are bulky, and it's better to have as few of them as possible. On the other hand reinventing stuff is not recommendable, so I think there is somewhere a point of balance of cost and benefit.

To me, the need for that single interface doesn't outweigh the cost of bringing in a whole dependency. By large margin for that matter..

Enno Shioji
I didn't thiink I needed to justify all of the reasons behind my question, but my purpose is also to look for related code/ideas that might be helpful. I'm not adding a project dependency for one class.
Christopher Martin
I didn't mean to criticize you or anything. It's just that I found it not justifiable from a cost/benefit perspective. Guess I couldn't understand your question very well.
Enno Shioji
A: 

It would not make much sense to introduce a dependency on a 3rd party library just for one interface. It would be better to use an interface in the standard library. How about Map?

Predicate < A > extends HashMap < A , Void >
{
     public Void put ( A a , Void v )
     {
           // put your evaluation logic here
           return null ;
     }
}

But I really do not see how this helps anyone.

emory