I am working on one shopping application. I have a header which acts like a container. Sometimes it acts like a container for recommended product, sometimes for advertisement. Right now I am conditionally changing innerHTML of header container for displaying advertisement or recommended product. I may add more categories to display in the header. I kind of feel that this if else will grow with time. Specially every category for example advertisement has more priority than recommended product. So if I get both from the feed I will show advertisement not recommended product. I would like to know what will be the good design for implementing such kind of thing. Is there any design pattern?
Well champ, this "if-else" thing isn't certainly the best way. Especially in the actual page itself: it is better to keep this logic away from it and have it on the server side. It is better to use HTML/XHTML/JSF/JSP only to display things. Eventually, you might have an "if" there (e.g. to verify if the user can see a particular button), but the less logic you have on pages, the better.
But I think we could use more details to give you some advice. It looks like we're talking about something like an e-commerce, right? You have a page, and you have a header that displays things. Categories have higher priority than products. How do you decide what is going to be displayed on the header? I mean, is it based on the product that is being displayed? How does it work?
Cheers, Roberto Perillo
SCJP, SCWCD, SCJD, SCBCD
Anything worth doing well is worth doing poorly first. Just look at this tiny ad:
ScroogeXHTML - small and flexible RTF to HTML converter library