Design Pattern Classifications

2

My college professor passed the following classification of the design patterns:

  • Creation: Abstract Factory; Builder; Factory Method; Prototype and Singleton.
  • Behavioral: Bridge; Command; FlyWeigth; Iterator; Observer; State; Strategy and Template Method.
  • Structural: Adapter; Chair of Responsability; Composite; Decorator; Facade; Interpreter; Mediator; Memento; Proxy and Visitor.

On the internet I found the following about GoF standards:

  • Created: Abstract Factory; Builder; Factory Method; Prototype and Singleton.
  • Behavioral: Chain of Responsibility; Command; Interpreter; Iterator; Mediator; Memento; Observer; State; Strategy; Template Method and Visitor.
  • Structural: Adapter; Bridge; Composite; Decorator; Façade; Flyweight and Proxy.

Which one is correct? If you observe, some patterns that the teacher passed are in one classification, and the internet is in another. My question is which of the two is correct.

    
asked by anonymous 29.11.2017 / 04:14

1 answer

3

The standards in which there is disagreement as to the classification in your question are Bridge, Chain of responsibility, Flyweight, Interpreter, Mediator, Memento, and Visitor.

Let's start with the easiest:

  • The Chain of responsibility is intended to encapsulate sequences of behaviors . This pattern allows you to hang these behaviors on each other and still keep them isolated from each other, just like the links in a chain. As the focus is to encapsulate behaviors , this is a behavioral pattern.

  • The idea of Flyweight is to reuse and share class states to reduce memory consumption and processing. That is, it is an optimization that should not have an impact on the behavior of objects. So this is a structural pattern.

  • The purpose of the Interpreter is to define how an expression can be interpreted. That is, set what is the behavior of an expression. So this is a behavioral pattern .

  • Memento is a standard that aims to provide objects with the behavior of saving and restoring a saved copy without violating the encapsulation. Because the focus is to provide behavior to an object, this is a behavioral pattern.

  • Visitor is a standard that aims to provide a type of polymorphism called double dispatch , where behavior to be performed depends not only on the instance on which a method is called, but also the type of parameter used in the call. As the focus here is the polymorphic behavior desired, this is a behavioral pattern .

Now the most difficult:

  • Bridge is intended to provide two or more levels of implementation flexibility in a class hierarchy. I'll take the example SOen response , but give a little change in the example to make it a bit more real:

    Imagine that you are modeling geometric shapes that may have textures. With this, you can have an interface to a geometric shape with an implementation of circles, a rectangle and a triangle. However, create a striped triangle, a triangle with a gradient, a triangle with a single color, a striped rectangle, a gradient rectangle, and so on. would be an exaggeration. The solution is you define an interface for the texture and say that a geometric shape has a texture.

    The problem to be solved is to provide multiple behaviors distinct from a class, but the problem that this pattern seeks to solve is not how to give these behaviors to the class but how to organize That's all. For this reason, this is a structural pattern.

  • The Mediator is intended to encapsulate the behavior of two objects that should not be known directly (which is a structural issue). The reason it's considered behavioral is because its idea is to encapsulate behaviors .

That is, the rating you found on the internet is correct.

    
29.11.2017 / 06:41