Consider the following short problem descriptions. For each, what design pattern
ID: 3836223 • Letter: C
Question
Consider the following short problem descriptions. For each, what design pattern would you use? Explain how this would work and why it is a good solution. a. A company has a system that has been working well for many years. They now want to add some functionality to that system without changing the current functionality. What structural design pattern would be most appropriate for this? b. A company wants to create a sophisticated inventory management system. Their inventory consists a collection of items. Some of these are fairly simple; others are complex collections of other smaller parts. They would like to structure this so that, when they use an iterator to traverse the inventory (for example, to print a catalog of all of the parts), they can treat each component uniformly. What structural design pattern would be most appropriate for this? c. For the inventory management system, the company needs to routinely apply specific operations to each inventory item. That is, at the beginning of the month, they have one particular operation that applies to all items. Later in the month, there may be another such operation to apply to all items. What behavioral design pattern would be most appropriate for this?Explanation / Answer
a)Decorator structural design pattern is used to add new functionality with out changing the current functionality.It is also known as a wrapper which adds additional behaviour to the class by wrapping it.This can be done statically or dynamically at run time.
b)Composite structural design pattern treats simple and complex parts unoformly.A group of similar objects are composed and treated as a single object.It is less complex to treat composites than primitives.The composite objects must have a has-a relation ship between them exhibiting similar functionality.
c)command pattern is a behavioural pattern used to execute commands at a choosen time.The sequence of actions are represented as command objects.The commands are stored in a stack and can be repeated again in sequence.new commands can be added or already present commands can be deleted from the stack.This is also termed as master worker pattern.