• Artima.com - tech-oriented blog directory

    Inspired by java.blogs, Bill Venners has set up Artima Weblogs for tech-oriented blog owners to submit their blogs so that it appears on an aggregated list. It does need a little redesign to make it look less "academic" though.

    I've signed up on the Open Source forums (only 3 of us at the time of writing).

  • Multi-author java tips blog

    I'm toying with the idea of a multi-author Java tips blog, and am looking for possible contributors. If there is sufficient interest, I'll be able to setup a subdomain to host the blog.

    Please do contact me at redemption at codefront.net should you be interested. This is (what I foresee) a good opportunity to share your experience and expertise with the Java community via the informal weblog medium.

    UPDATE: I've setup a subdomain at http://javatips.codefront.net/.

  • java.blogs gets confused

    java.blogs apparently gets confused when I updated the title of a blog entry - the updated blog becomes the newest entry and my subsequent blog entry does not appear on the java.blogs front page, nor on the blog details page.

    I apologize to java.bloggers for being lead to my old entry yet again.

    I may yet have to re-add by blog unless this fixes itself soon. (It's an unresolved issue.)

    EDIT: It appears that an update of my blog details fixed the problem.

  • Java Tip #2: Static factory methods vs. constructors

    Factory methods are simply methods that instantiate objects. Some factory methods in the Java 2 API that you would likely have used are the getInstance() and valueOf() methods. getInstance() is the conventional instantiation method in singletons, while valueOf() are often type-conversion methods, like in String.valueOf(int i).

    Providing a static factory method instead of a public constructor has both advantages and disadvantages, which will be discussed at length in the rest of this entry.

    Static factory methods have names
    A class can have only a single constructor with a given signature, which is a restriction in cases where a class needs to be able to be instantiated using identical parameter lists. In cases like this, you can replace constructors with static factory methods with more intuitive names that highlight their differences.

    Static factory methods can improve performance
    This is because static factory methods do not have to actually instantiate new objects each time they are invoked. This is what allows for the Singleton pattern, where a single instance is returned. It also allows instances to be cached within the object in cases where object instantiation is expensive (like for the case of instantiation of fields from a database) or frequently done.

    Static factory methods can return a subtype of their return type
    This allows for interfaces to be returned by static factory methods, which is best exemplified in the Collections Framework. Needless to say, forcing a client to refer to the returned object by its interface rather than its actual class is a good practice.

    Also, the class of the object returned can be private (non-public), so there is a degree of encapsulation where the private class can be modified without impacting clients of the API (possibly for bug-fixing or improvements, or just plain maintainence). The private classes can also vary depending on the parameters to the static factory, so long as they are subtypes of the return type, allowing for greater flexibility.

    Classes without public or protected constructors cannot be subclassed
    This is an unavoidable fact, so classes designed for inheritance must have at least 1 public constructor to be able to be subclassed.

    The verdict? Use static factory methods for a more intuitive API, to improve performance via object-caching, to implement singletons, in interface-based frameworks, and to return objects of private classes. Use constructors in classes designed for inheritance (there shouldn't be many of these) and for greater visibility in API documentation (since they appear in a separate table in standard Javadocs).

  • CMS - Mambo Open Source 4.5

    Looking forward to the release of Mambo Open Source 4.5. From the screenshots here and here, it looks very promising, and most important of all, easy to configure, administer and use without requiring a messy or non-intuitive process.

subscribe via RSS