The Basic Design Patterns All Developers Need to Know

The Basic Design Patterns All Developers Need to Know

They are design level solutions for recurring problems that us software engineers come across often. It’s not code, I repeat, CODE. It is like a description on how to tackle these problems and design a solution. Using these patterns is considered good practice, as the design of the solution is quite tried and tested, allowing higher readability of the final code. Design patterns are quite often for and used by OOP Languages, like Java, which most of the examples from here on will be written.

This is a companion discussion topic for the original entry at
1 Like

Doing business on illegal coffee will get you nowhere.

Great article! Loved the addition of the thread-safe version of Singleton.
In my opinion you should have shown the need or the problem that Command resolves a bit more, like you did with the example of Decorator and the 324 subclasses.
Thanks a lot!

I’m confused why in the second example AddOn has the description argument. It is just passed up to the Beverage constructor and assigned to the private description field which isn’t accessible by AddOn because AddOn overrides Beverage’s getDescription() method which is the only use of the private description field of the Beverage class.

very nice article!! Cheers!
just a little remark about the command pattern, I think the Waiter should hold a list of order, and this same list is created empty with Waiter constructor. A Waiter constructor getting Order as argument seems inefficient since we don’t want to create a waiter for every new order. Instead, we should have a takeOrder function in Waiter class.

Thank you,
N. Perez

Actually, it’s worse: 450 subclasses. (450 = “10 choose 2”) You have 10 choices for the first add-on then 9 choices for the (10 minus the one you chose). 10x9 = 900. Then divide by 2 because of duplicates (ie “milk with sugar” and “sugar with milk”).

Thanks for the article, great coverage of the Singleton pattern. I wanted to add to the discussion of the Command Pattern by re-implementing the code example but using separate Command objects. In this case:

  • CookPastaCommand
  • BakeCakeCommand

Code on Github