3

Hi I am learning design patterns from a book . How to figure out the actual production code where it is implemented .

For example , if I am learning strategy pattern , it might be implemented in Spring framework . But how to go and search there and see it .

Do you guys have any easy ways of finding such stuff ?

2

You often don't need to see the code to have a good idea of what pattern is being implemented. What's important is how the classes interact with other objects, and that you can deduce from looking at its Methods and Properties.

For example, lots of C# and Java Libraries have classes where there is not a constructor for the class, but there is a "CreateWidget()" function which returns a new Widget dependent on some parameters you pass that function. That is an example of a "Factory" pattern.

1

It's the other way around. You shouldn't code based on a design pattern. Pattern emerges in your code. It's then you make the code more general and make it based on a design pattern. When you start repeating yourself then you should ask your self if there isn't a pattern that should fit the problem.

0

In general Books about design patters show an actual implementation in some language (Like Gamma's Design Patterns).

If your looking for implementations of design patterns on a certain software its a bit harder because each implementation not always follows the exact same patter. I think one way to find them is trying to look for parts of the software that resolv esome kind of generic problem (like rendering a window is most probable that uses a composite pattern).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.