What design scheme should I use in this matter?

To be honest, this is a matter of homework, so I will tell you my opinion. Can you tell me your mistakes and not give me a solution?

This is the question:

Imagine a restaurant that offers only the following two types of food: (a) full lunch and (b) housekeeping. A complete meal consists of the following foods and is served in the following order: 1. Appetizer 2. Drink 3. Main course 4. Dessert Meanwhile, household food consists of the following foods and is served in the following order: 1. Drink 2. Main course

Determine the most appropriate design pattern that can be used to allow the customer to only order using one of two types of meals and that the food components should be served in that order.

I got confused between Factory and Iterator and used them together. Using the Factory template, we can create a complete and economical power supply and provide the user with a base class of objects that will be solved. But how can we ensure the ordering of the elements, I thought about using an iterator that will go through a composition of two created factories, like saying.

What do you think?

+8
design-patterns software-design
source share
3 answers

The first thing that comes to mind is the Decorator pattern. So you can create a food base and 2 non-alcoholic dishes FullMeal and EconomicMeal, then you can have the food components as decorators and mix and match them as you wish.

+1
source share

This is a two-step process, and I think you're confused. The main thing they are looking for is a template that you will use to select the logic that the user will order. What this logic actually does, or what kind of meal order is served, does not apply to this part.

So, you will have a basic Meal interface or an abstract class that has a method or methods for placing an order (it does not say that food should be requested in the order it was served, or you will note). This Meal class is likely to have several methods, one of which includes ServeFood () or similar. You will have two specific classes for this (for example, FullMeal and EconomyMeal), and since their order is not important, you can implement it with Factory.

Specific classes will be responsible for serving food in the correct order when ServeFood () is called on them.

+1
source share

I think the homework is poorly worded. As quoted here, I see no problem.

Define ... a design template that you can use to allow the customer to order only one of two types of dishes

What is the problem? Just present to the client a choice of 2 options ( "choose meal type (1-full, 2-economy): " and you're done. Why do you need a design template for this?

Design patterns are a tool for a programmer / designer, not a user. Therefore, the correct (IMHO) question should be "suggest design patterns that will allow the programmer ...", for example. "... combine / modify the type of food based on data from fixed types of dishes" or something like that.

As said, the question does not define the programming / design problem or does not accept too much noise.

-4
source share

Source: https://habr.com/ru/post/650852/


All Articles