Feb 26
Functors are defined as a function encapsulated in an object. In most cases, the function’s parameters can be set and the result retrieved using the common accessor pattern, such as setParameter1(Object value) or getResult(). The fact that these functions are encapsulated by real objects is also the reason for its greatest benefit: the use of many design patterns including structural ones such as the Decorator pattern and behavioral ones such as the Visitor pattern.
Functors in software design
While the classic object oriented design encourages inheritance and method overloading to achieve code reuse and code specialization, the functors’ design promote another approach, of composition. Functors are created to accomplish simple tasks and are later connected together, by connecting one functor’s result to another’s parameter, to satisfy a greater goal of the application.
Continue reading »
Dec 22
Isn’t it about time we got to know the different stream classes a bit better? We use them in almost every project, but what do they mean? How should can we use them more efficiently? And what is the difference between a Reader and an InputStream anyway? I hope I’ll manage to give the answers I’ve come across from using, implementing and reviewing other implementations of these extremely useful classes. Continue reading »
Apr 01
In my project,
Xml2Java, I had need for a code that checks reflection information, specifically methods and fields, and operates on relevant ones. For example,
I wanted the code that analyses the elements and attributes of a complex element
to work only on getter methods, that is, methods that begin with “get” or “is” and return a boolean.
At first, the code looked like this:
for (Method method : clazz.getMethods()) {
if (method.getName().startsWith("get") ||
(method.getName().startsWith("is") &&
method.getReturnType().equals(Boolean.TYPE))) {
// do stuff
}
}
Continue reading »