Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Which of the GoF patterns could you not live without?

If, in future, you were only able to use a single one of the canonical patterns defined in the Gang of Four book, which one would you choose and for what reason?

like image 286
Stu Mackellar Avatar asked Jan 31 '09 00:01

Stu Mackellar


People also ask

How many GOF patterns are there?

There are 11 behavioral design patterns defined in the GoF design patterns. used to create a template method stub and defer some of the steps of implementation to the subclasses. used to provide a centralized communication medium between different objects in a system.

Which pattern is not a category of GOF patterns?

Explanation: Creational Patterns for the creation of objects; Structural Patterns to provide relationship between objects; and finally, Behavioral Patterns to help define how objects interact. and this does not include user defined, because Java is not a valid classification of designed patterns.

Are GoF Design Patterns still relevant?

Since its release in 1994, the Design Patterns book continues to be a seminal work in building software. The book created a new shared vocabulary and named these repeated solutions we see all over different codebases.


2 Answers

Not a design pattern, but to me this principle was definitely the most influential on my programming style of the whole book:

Favor object composition over class inheritance.

Combined with the other principle "Program to an interface, not an implementation", most design patterns follow naturally.

Choosing one pattern as the most important is in my opinion impossible. They all have their purpose and complement each other. Its like asking if a hammer or a screwdriver is more useful. It depends on the problem, sometimes you have a nail and sometimes a screw.

like image 179
martinus Avatar answered Oct 15 '22 19:10

martinus


Abstract Factory Pattern or Template Method Pattern... but mostly Abstract Factory Pattern. They have just been extremely useful on a lot of situations.

I specially liked the way Abstract Factory allows you to prepare for situations where you know your program may change in the future by following the same rules in a different way.

Is mostly like the Abstract Class allows you to define specs "inside" the code, restrain the code to follow that specs while the factory allows you to "choose" among those specs. Simply beautiful.

like image 31
Jorge Córdoba Avatar answered Oct 15 '22 18:10

Jorge Córdoba