For example I can have something like so,
A
B
ba
bb
C
Ca
D
Right Now I have a 2D array,but this isn’t very general, because I would need another dimension if I wanted to extend the maximum sublevel from 2 to 3. Any suggestions?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
The Composite Pattern would be an appropriate application here:
(From wikipedia:) http://en.wikipedia.org/wiki/Composite_pattern
In your case:
You can achieve desired ordering of menu elements based on their insertion order into a Composite “SubMenu” by implementing a counter with each SubMenu object: each time you call
aSubMenu.add(newMenuItemOrSubMenu),aSubMenushould increment its own counter and tag the new item with the ordering number. (Exact detail of the implementation is up to you, you don’t have to use separate counter at all and just use a list or an array)