Advanced SiteMesh Article George W Bush and John Kerry are both Essex Boys!
Sep 23

Encapsulating Generic Types

Tech Add comments

I am a little scared of Generics (as you may have noticed).

I see some value, but I also see two problems:

  • Some programmers don’t/won’t get it
  • Holy readability batman!

As a way to help readability, AND to allow you to make changes to your codebase easier, I think it is often wise to encapsulate your Generic types.

Cedric did this very thing.

This is very ugly isn’t it?

Map<String, List<Account>> accounts = new HashMap<String, List<Account>>();

So encapulate:

class AccountMap extends HashMap<String, List<Account>> {


Not only is it nicer to work with in your code now, but you can add functionality to the AccountMap if it makes sense. And all of your code gets the new functionality.

One Response to “Encapsulating Generic Types”

  1. Brett Porter Says:

    ah, having actually read Cedric’s blog I now see that that is what he was trying to avoid.

Leave a Reply

Spam is a pain, I am sorry to have to do this to you, but can you answer the question below?

Q: What is the number before 3? (just put in the digit)