Design Patterns again? Yes!

Dolly Desir
2 min readFeb 1, 2021

--

There are so many design patterns! Behavioral has 10, Structural has 7 and finally Creational with 5. That’s a total of 22 designs patterns and because I love building beautiful apps, I really want to dive into all of them. One of the things I try to keep in mind for myself is always writing code that someone else can understand & implementing best practices in my code. These design patterns are solid approaches that solve issues in a widely accepted way and reflect the experience and insights of the industry-leading developers that helped define them. That being said I want to make sure I have a clear understanding and the best way to do that is to explain it!

I’ve discussed all of the Creational design patterns, now I will get into Structural design patterns and how I understand them. The first pattern I will go over is the Adapter Pattern, this pattern is very clear and concise in its purpose. An adapter in the real world allows you to use 2 things that aren’t compatible with each other.

An example for using this pattern in OOP, whether it’s a library, interface or an API that's older yet still in use but some parts have been updated. Below is a code example that I found that explains it pretty clearly with code.

Soumyajit Pathak perfect coding example of Adapter Design Pattern.
CalcAdapter taking in both functions of the OldCalc & NewCalc.

An adapter wraps one of the objects to hide the complexity of conversion happening under the hood. The wrapped object isn’t even aware of the adapter.

I’m finding it Structural Design Patterns to be much harder to understand and implement than Creational. I started with Adapter first because I found much easier to understand than the but next week I will hopefully dive into understanding 2 more Structural Design Patterns! Thanks for reading!

--

--

Dolly Desir
Dolly Desir

No responses yet