From a bookish perspective, you might say that x design pattern is applicable in y scenario, but I want to dig a little deeper here. So here are my queries:
Edit:
I'd like to add that I read DPs through "Head First Design Patterns" and although it's one of the best books to understand the pattern. I don't think I've been able to transition the Pizza examples to real world scenarios.
I think this is one of the most influential books on DP but we can still have a book that may enumerate the various popular business scenarios that demand a particular pattern alongside that pattern. This knowledge is still implicit to a large extent I think. Such a book would be a very nice quick reference don't you think :))
Design patterns provide a standard terminology and are specific to particular scenario. For example, a singleton design pattern signifies use of single object so all developers familiar with single design pattern will make use of single object and they can tell each other that program is following a singleton pattern.
Most of the time, the design pattern is used when it is clear that the developer needs its flexibility. Each design pattern has its own approach. The strategies present in each design pattern are therefore original and are never the same from one design pattern to another.
Design patterns are commonly defined as time-tested solutions to recurring design problems. The term refers to both the description of a solution that you can read and an instance of that solution as used to solve a particular problem.
A pattern is used as a template to cut out fabric that matches the required specifications to sew a garment. It factors in the type of fabric, the intended fit on the wearer, and any trims that will be used. The pattern is used to make 2D fabric sit properly on a 3D body.
It depends how you write the code. If it's a big project I decide before coding, then after I start writing the code, if I notice places where design patterns should be used, I refactor the code.
Yes, as mentioned before.
in 99.99% of the cases: Factory Pattern, Singleton (Like everyone I use it in many places because is simple to implement, and in practice I tend to remove it while refactoring the code). Then: Object Pool(if I have resources I want to reuse - some of my projects are games and I need a good management of resources), Strategy and Template Method (because they are great for decoupling and serve well the purpose to make the code easy to extend). Then the Adapter is something to use when you have a library you want to use, without relying on it(decoupling).
Same as Above, if I didn't use them yet. It works also in the opposite way. If I don't find the reason to use a design pattern I remove it or skip it while writing the code (it happens all the time with singleton and from time to time with factories. Sometime I use a factory which is also a singleton to provide me those which were supposed to be singletons objects; not sure if it's wise thing to do, but it works for me).
The only code hint I might think it the number of references you have to a class. You can also use PMD, jDepend and Architecture Rules to spot the places where the classes contains too many dependencies. I'm not sure it this is a coding tip. In the design phase and not only there when you decide to use a design pattern just think to the benefits. I found that Software Design Principles are extremely important to help you understand when and why (not) to use a design pattern, but they are unknown to many programmers who are using design patterns.
I'm not sure what do you mean by Micro DP. I'm trying to use DPs only when I find reasons to use them and when the benefits seem to be bigger than the problems. I avoid the overuse because it leads you to loosing time implementing and maintaining factory patterns instead of real software.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With