Win a copy of The Business Blockchain this week in the Cloud forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Mark Cade's Study Guide p. 87 Q3: Pattern for Additional Responsibility

 
Darya Akbari
Ranch Hand
Posts: 1855
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

please view the following question from Mark Cade's SCEA Study Guide p.87:


Which pattern allows for addition of responsibilities?
  • A. Proxy
  • B. Fa�ade
  • C. Decorator
  • D. Strategy
  • E. Adapter



  • What's the correct answer? Please with a small explanation .

    Regards,
    Darya
     
    Tom Adams
    Ranch Hand
    Posts: 56
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Out of the 5 patterns listed Decorator is the only one whose intent is to add responsibilities. This seems a bit confusing because the decorator does not change the interface of the class it is decorating...I guess it means it can add additional logic to an existing method.

    Proxy - provides a surrogate or placeholder object to control access to the original object.

    Facade - defines a higher-level interface that makes the subsystem easier to use.

    Decorator - attaches additional responsibilities to an object dynamically to provide a flexible alternative to changing object functionality without using static inheritance.

    Strategy - allows you to change the behavior of a class by plugging in different method implementations.

    Adapter - Adapter pattern acts as an intermediary between two classes, converting the interface of one class so that it can be used with the other.
     
    Darya Akbari
    Ranch Hand
    Posts: 1855
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Hi Tom,

    thanks for the pattern details. I agree with you concerning the confusion .

    To me the Strategy pattern was the one that can add responsibilities. Because I really understand the question in a sense that how to add new behavior.

    But from the wording of the answers I am a little bit afraid that one has to memorize the exact wording as provided in Mark Cade's SCEA study guide

    Regards,
    Darya
     
    Peer Reynders
    Bartender
    Posts: 2968
    6
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Originally posted by Darya Akbari:
    To me the Strategy pattern was the one that can add responsibilities. Because I really understand the question in a sense that how to add new behavior.


    But the Strategy pattern isn't about adding new behavior - its more about making aspects of behavior exchangable. GOF's pr�cis for Strategy is:

    Strategy (315) Define a family of algorithms, encapsulate each one, and make them interchangable. Strategy lets the algorithm vary independently from clients that use it.
     
    Darya Akbari
    Ranch Hand
    Posts: 1855
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Hi Peer,

    with behavior I mean a family of algorithms exactly as the GOF definition for Strategy Pattern.

    Regards,
    Darya
     
    Peer Reynders
    Bartender
    Posts: 2968
    6
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Originally posted by Darya Akbari:
    with behavior I mean a family of algorithms.


    I wasn't quibbling about that.

    Imagine a pastry creme bag with shell, star, and leaf nibs (decorating tubes). You do not use the bag without nibs and you basically use the pastry cream bag in a similar fashion with each nib. However each nib produces a differently shaped stream of pastry cream - each nib represents a different Strategy.

    You usually buy a KitchenAid/Cuisinart kitchen machine to mix batter and knead dough - thats its primary job. But you can get an attachment for it to grind meat/shaping sausage - that attachment is more like a Decorator. It would be a proper Decorator if you were shaping sausage and kneading dough at the same time (not very sanitary though).
     
    • Post Reply
    • Bookmark Topic Watch Topic
    • New Topic