So, let's say you are building a custom website (not one who's navigation is managed by any other component, such as a CMS). And the navigation is more than just 5 tabs on the top of the page, it includes some side navigation, possibly with multiple levels.
You think you can just put all the navigation inside of HTML or some other UI layer (JS or otherwise), but I'm here to tell you, you CAN'T. Well, you can, but you'll regret it.
Eventually, you will wish you created a NavigationManager class that looks something like this:
public class NavigationManager {
public static Instance { ...} //yes, maybe it's a singleton
public NavNode HomeNode;
}
and a NavNode object that looks like this:
public class NavNode implements INavNode
{
public NavNode[] NavNodes;
}
The reason for this is:
- You can generate the nodes based on an XML file or Database or something else
- You can cache them in .NEt in System.Cache or java using EHCache (or something else) or just plain use a Singleton
- You will need it to build the sitemap
- You will need it to build a breadcrumb
- Your users will eventually want some new crazy flash UI or ajax UI to have the navigation open and collapse so you better keep your data and logic separate from the UI.
Navigation is one of the most pervasive AND most likely things to change on your site so it's best to separate it as cleanly as possible from the rest of your application.