I have a design problem:

A site I'm working up has a shell/module structure. Each module composes an instance of a Navigation class.

This instance mixes and matches various navigation functionality. Some modules might have last/next methods, some might have last/next and direct goto (buttons) methods, some might have just goto (buttons), or buttons and browser-like, history-based forwards/ backwards methods. Some will have pause/play. Some might have no navigation at all. All would have an index property and an abstract "goTo" method, which would be handled/implemented by the module itself.

When the module is focused, a controller bar in the shell redraws itself according to the module's navigation.

Here's two questions:

1) How do I make this navigation object? It mixes and matches a set of methods almost randomly. It this even a candidate for a class?

Having just read Head First Design Patterns, my first thought was that decorator could help. But how do you access added methods if the basic object is wrapped more than once:

NextLast(History(new Navigation())).goBackward() wouldn't work because goBackward is not a method of the outermost wrapper, NextLast.

Should I then make the decorator specify ALL possible methods? That seems perverse.

Instead, it would be easier to supply a full-fledged navigation object and selectively enable parts of it. But then the class would turn into a mess of conditionals:

function next() {
currentIndex++
if (this navigation instance has a history) {
history.push(currentIndex);
}

This is stumping me. Having pattern fever (I recommend the book), the only alternative I can think of is: turn each piece of navigation functionality into a class (history, nextLast, etc), then compose a navigation object as an array of objects, which would each in term handle a message from the controller in the shell (chain of responsibility?).

2) Once I manage to compose a navigation object, how can the shell's controller bar interrogate it? That is, how to know which methods are defined or enabled for it? Is there a more direct way than looping through the object and looking at its properties and methods (and since I'm doing this in AS3, I'm not sure I can even do this). I suppose I could store a bunch os strings for verification, but as with the last problem, I can't believe that smarter programmers haven't solved this problem in an better way.

I should say that the site is mine and the only constraint is the spec I'm giving myself, which is: give every module a navigation module, so that the module's navigation will be easy to create (new History(new Navigation)), without having to create a bunch of new classes (HistoryNextLast extends History). In addition, I want the the navigation object to refer back to other navigations objects so that they form a XML-like nodal structure. This would be convenient for retrieving navigation information, but even more for creating an easy add-on structure. Basically, I want any combination of nav functions to be able to lead to any other kind of combination, module after module. How to achieve this I don't know yet.
_______________________________________________
[email protected]
To change your subscription options or search the archive:
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders

Brought to you by Fig Leaf Software
Premier Authorized Adobe Consulting and Training
http://www.figleaf.com
http://training.figleaf.com

Reply via email to