Interfaces for Command Pattern in Java
Asked Answered
M

1

6

Is there a library out there that already provides the interfaces we need for the command pattern in Java?

For example:

 public interface Func1<T,R> { public R execute(T input); }

 public interface Func2<T1,T2,R> { public R execute(T1 input1, T2 input2); }

 public interface Predicate1<T> { public boolean execute(T input); }

 ....

Thanks.

Mei answered 1/5, 2012 at 22:3 Comment(2)
This doesn't look like a command pattern library, this looks like a functional programming library.Worser
Try Guava, they have Predicate and might also have those others.Fellah
H
6

Guava has your first and third interfaces (called Function and Predicate). Your second one, IMHO, is not useful, because you would just have to combine T1 and T2 in a single object, and use the first interface instead.

More interesting, Guava also has a whole lot of methods using these two interfaces, like Iterables.any(Iterable, Predicate), Iterables.transform(Iterable, Function), etc.

Hebetic answered 1/5, 2012 at 22:10 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.