First and for most - I would love to hear your thoughts on
When in ones developer journey should one look into the topic of patterns?
As of my opinion is as early as possible and here is why! 😊
Development can be simply descripted as solving problems and occasionally drinking coffee ☕, and although this is what we as developers do and also what we hopefully enjoy doing, there is not always a need for that. Why you ask? Well, firstly that in your hand is properly not your first one of the day, and secondly lots of people, especially four very dedicated man, already did a lot of thinking for you 🧠.
Do not get me wrong, finding your own way of problem solving and kind of developing a 64-bit sense for it is a crucial skill you need as a developer, yet I think especially for beginners it is not any less interesting as it is educational to see how other people approach all sorts of problems.
When talking about design patterns in software engineering the Gang of Four Design Patterns are what most people think of. Those are your
goto for any sort of somehow generic problems like...
Factory Method: To create instances of different implementations of an interface.
Composite: To compose objects into tree structures and work with these structures like with individual objects.
Iterator: To iterate all elements of a collection without exposing their underlying representation.
Just to give a quick overview on those patterns, there 23 of them, categorized into:
- Creational Patterns
- Structural Patterns
- Behavioural Patterns
In the book Design Patterns: Elements of Reusable Object-Oriented Software each pattern is descripted and exemplify with UML diagrams, template source code and a real-world example. It is very well-written and gets you right into the different topics and use cases.
Back in school, my professor always did the following three-step-approach of showing us the purpose of a new pattern:
- Explain a problem
- Give time to the students to come up with their own solution
- Discuss the approaches and present the pattern-solution
I loved this technique of him teaching us as we were given the chance to think about a problem and understanding it as a whole. Additionally, since then I always had a distinct example for every pattern in my mind!
So, now that you got all your sources of information ready, maybe even a collection of code snippets and explanations, what next? Think through them, maybe find real-life examples based on your own experience and code, code, code as one of my professors always used to say:
I didn’t really understand it - until I tried it!
Design patterns are a great thing to know. They make the life of a developer much easier and are optimal against headaches and bad code design, yet bear in mind that these patterns should support you and you should not just blindly follow along.
Understand what code can do and what you can do with code!
Ps.: Also an amazing tip in terms of improving your coding skill and the overall quality of your code is the Clean Code Initiative providing the theoretical input and also a roadmap on how to go about it.