views:

84

answers:

4

Is there way to better identify design pattern in source codes, esp. if you are not familiar with all of the patterns? What's the best way to identify them?

+3  A: 

What do you mean? You identify them by knowing them, and then seeing the signs of one, and putting the pieces together.

Sometimes the name is indicative, FooFactory, etc.

There's no "magic". I don't quite understand the point of this question ...

Noon Silk
Sorry if my question is not so clear. I was wondering if there's a way you can better classify to what kind of pattern it actually is like behavioral, structural, etc. and narrow it down to the exact pattern. I'm asking this as a beginner learning patterns, not so much familiar with them and I have to identify some in a short time.
jasonline
@jasonline: I don't know of any tool that is written to determine what design patterns are being used. It's possible (I suppose) to write such a thing. Maybe it would be interesting, maybe not. But there is no way to determine "patterns" as opposed to "code". Patterns are just *ways* of writing code; so you can detect them in your brain, or write the processes your brain goes through into code, and develop a tool to do it :)
Noon Silk
@silky: I see, I guess it's best you have to be familiar first before you will be able to identify one then, rather than the other way around.
jasonline
@jasonline: Indeed :)
Noon Silk
+1  A: 

A design pattern is a piece of code / architecture, designed to solve a certain problem, that is useful and abstractly applicable to the same problem in other domains. If you see the same kind of code/architecture used in multiple places, it's probably a design pattern, albeit not necessarily a Gang of Four design pattern

Jimmy
A: 

One of the most important things design patterns has given us is a more unified vocabulary. Any (well-written) code that uses a particular design pattern should identify the name of the pattern somewhere.

Jon Reid
A: 

I would start with becoming familiar with Code Smells. It is very typical that a pattern will improve/remove a code smell. Another great resource with some real work examples is the Refactoring to Patterns book. The book shows code with smells and how to fix them with patterns.

Adam Fyles