As an exercise to better comprehend design patterns, we were given the restaurant context. A client places an order and the restaurant prepares the order.
To decouple Customer and the OrderProcessor(which holds a list of customer orders), I used a mediator. The mediator in turn uses the Build pattern to create a list of ordered items.
Also, the restaurant has a menu which in turn has a list of menu items that can be single items (burgers, fries etc.) or combinations of single items (trio). I thought of the composite pattern when I read this. Initially, I thought of creating a MenuItem interface and have a ComponentItem and CompositeItem class implementing MenuIten interface. Also, I would create a OrderedItems class (list of ordered items - created by the Builder) which would be aggregated into a CustomerOrder class (Command).
I do not know if my approach is correct. If I am not mistaken, this would mean that both Menu and OrderedItems would contain a list of MenuItems.
I apologize if my problem description and my understanding of design patterns leaves much to be desired. It is my first semester in software engineering and first exposure to the patterns world.
An important concept about software design, including the usage of OO design patterns, is that there is no "correct" design and "incorrect" design. If a particular design fails to meet the particular requirements, it is void and should not be considered. There typically will be many, many ways to implement a set of requirements, and all of them will work. What you need to figure out is which one is "best" for your situation?
While many implementations will "work", as you dig deeper you will find some that will be problematic in terms of maintainability, manageability, security, scalability, extensibility, performance, etc. In the beginning, this is not an easy task for the novice. You will need to develop the ability to effectively balance theory and the realities of your particular situation (costs, resources, time, etc.) to determine which one is "best", not which one is "correct."
Hope this helps. Good luck!
Joined: Oct 18, 2010
Thank you Jimmy Clark.
I must admit that as a novice in the realm of Design patterns, I feel at times overwhelmed at the choices offered but more importantly with the possible combinations possible. I realize with experience the process may feel somewhat smoother.
Because this is a purely academic exercise, we (students) tend not to give much thought about the realities of software development, time and budgets. We simply spend as much time as needed to complete labs and assignments.
I also thank you for pointing out that there is no magic solution but rather a set of functional solutions where some are better than others.
Again thank you for your remarks and advice.
subject: Quick questions on pattern use - (restaurant example)