Flag%20question%3A%20Question%203%0AQuestion%203%0A2%20pts%0AWhich%20of%20the%20following…
- User
Flag%20question%3A%20Question%203%0AQuestion%203%0A2%20pts%0AWhich%20of%20the%20following%20are%20advantages%20of%20using%20the%20Decorator%20pattern%3F%20Select%20all%20that%20apply.%0AGroup%20of%20answer%20choices%0AReduces%20coupling%0ADecreases%20cohesion%0AAllowing%20the%20behavior%20of%20multiple%20objects%20to%20be%20changed%20at%20once%2C%20in%20the%20case%20where%20a%20decorator%20is%20wrapped%20around%20a%20collection%0AIncreases%20coupling%0AAvoiding%20an%20exponential%20number%20of%20subclasses%20that%20might%20be%20made%20if%20using%20inheritance%0AIncreases%20cohesion
- Assistant
The advantages of using the Decorator pattern include:
-
Reduces coupling: The Decorator pattern allows for a more flexible design by enabling behaviors to be added to individual objects without affecting others, thus reducing the coupling between classes.
-
Allowing the behavior of multiple objects to be changed at once, in the case where a decorator is wrapped around a collection: This is an advantage as it allows for dynamic changes to the behavior of grouped objects through a common decorator interface.
-
Avoiding an exponential number of subclasses that might be made if using inheritance: The Decorator pattern prevents the need for an immense number of subclasses that would be required if trying to achieve similar functionality only through inheritance.
The incorrect options are:
- Decreases cohesion: Using the Decorator pattern typically increases cohesion as classes focus on a single responsibility.
- Increases coupling: The Decorator pattern is designed to reduce coupling, not increase it.
- Increases cohesion: This statement is generally incorrect in the context of the Decorator pattern.
So, the correct answers are:
- Reduces coupling
- Allowing the behavior of multiple objects to be changed at once
- Avoiding an exponential number of subclasses that might be made if using inheritance
-