When to use a design template?

I really like design templates, but it's hard for me to understand when I can apply them. I read a lot of sites that explain design patterns. I understand most of them, but it's hard for me to recognize the pattern in my own situations.

So this is why I am asking this question. Are there any recommendations / signal bells when to use a design pattern.

For example, if you execute a switch statement to determine which object you want to create, you probably want to use the factory design pattern. Thus, the switch statement in this case is a "signal call" to use the factory pattern.

So, do you know more โ€œalarmsโ€ to define a design pattern?

+75
c # design-patterns
Feb 18 2018-11-18T00:
source share
5 answers

To get started, just take a look at this page: http://codebetter.com/jeremymiller/2006/04/11/six-design-patterns-to-start-with/

While Jeremy is dealing with several sets of templates here, you should read these articles and then follow this: http://codebetter.com/jeremymiller/2005/09/01/learning-about-design-patterns/

Also use the links to this article (especially the Eric Gamma interview) and you should be installed.

+23
Feb 18 '11 at 10:03
source share

Usually the process is the opposite. Do not go in search of situations where to use design patterns; look for code that can be optimized. When you have code that you think is not structured correctly. try to find a design template that will help solve the problem.

Design patterns are designed to help you solve structural problems; do not design your application to use design patterns.

+74
Feb 18 2018-11-18T00:
source share

Examine them and you can slowly change and find out when to use them. Start with something as simple as a singleton :)

if you want to create one instance of the object and just ONE. You are using a singleton pattern. Let's say you make a program with an options object. You do not want some of them to be stupid. Singleton is sure that there will never be more than one. The Singleton template is simple, used a lot, and really effective.

+4
Feb 18 '11 at 10:01
source share

I totally agree with @Peter Rasmussen.

Design patterns provide a common solution to a frequently-encountered design problem.

I would like you to follow below.

  • Understand the intent of each template
  • Understand the checklist or use the case of each template
  • Think about a solution to your problem and see if your solution falls into the checklist of a specific template.
  • If not, just ignore the design patterns and write your own solution.

Useful links:

sourcemaking : explains purpose , structure, and checklist nicely in several languages, including C ++ and Java

wikipedia : Explains the structure, UML diagram, and working examples in several languages, including C # and Java.

Checklist and Thumb Rules in every sourcemakding design-pattern alram bell you are looking for.

+3
Jun 14 '16 at 16:48
source share

Although the old thread, if you are looking for something in .NET, use this extremely useful .NET Design Patterns article in C # that shows how to use them in the real world. NTN!

+1
Oct 10 '16 at 12:04 on
source share



All Articles