• Post Reply Bookmark Topic Watch Topic
  • New Topic

What if there are too many number of cases of input, what design pattern should I use?  RSS feed

 
Byeonggon Lee
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
For example


if I choose hamburger there are choices again

If I choose big mac there are choices again!!.


situations like this, what design pattern should I use?
 
Junilu Lacar
Sheriff
Posts: 11494
180
Android Debian Eclipse IDE IntelliJ IDE Java Linux Mac Spring Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am not aware of any design pattern that can be applied to this context. Your description does hint at a hierarchy of options though. There are a number of data structures that you can use to help you manage this hierarchy, including Maps and Lists.
 
fred rosenberger
lowercase baba
Bartender
Posts: 12565
49
Chrome Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Byeonggon Lee wrote:
If I choose big mac there are choices again!!.


Are the drink choices really contingent upon what food and burger type I choose?
 
Byeonggon Lee
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Are the drink choices really contingent upon what food and burger type I choose?

Nope drinks are independent

Second input depends on first input, but third input is independent
 
Junilu Lacar
Sheriff
Posts: 11494
180
Android Debian Eclipse IDE IntelliJ IDE Java Linux Mac Spring Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think a Tree suits this best. A Tree is made up of Nodes, with each Node representing a menu item. A Node will point back to its parent. Top-level menu items will have no parent. To find items in a second-level menu, you search for nodes that have a parent in the top-level menu. To find third-level menu items, you search for nodes that have second-level parents. In general, to find N+1 level menu items, you look for nodes that have an N-level parent.

For instance, Hamburger, Pizza, Chicken, Sandwich, Drinks will all be nodes with parent == null.

Big Mac, Quarter Pounder, etc. will be nodes that have Hamburger as their parent

Coke, Orange Juice, etc. will be nodes that have Drinks as their parent

and so on

Edit: If you want to use formal names, what I describe above is really a "Forest", which is a collection of Trees. In this case, the Trees are General (non-binary) Trees. Nodes that have no parent are called the "Root" of a Tree.
 
Byeonggon Lee
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think a Tree suits this best

Yep, I agree, I googled all day and it seems there is no alternative to tree or list. Now I'm working on the tree, thanks
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!