Design patterns are solutions to common programming problems that arise when developing software.
They provide a way to reuse successful designs and architectures in new projects, and can help you think about problems in a more abstract and flexible way.
By practising implementing design patterns in a new programming language, you can learn about the language’s syntax and features, as well as how to use them to solve real-world problems.
This can be a helpful way to get a feel for the language and become more proficient in it.
Additionally, understanding design patterns can make it easier to read and understand other people’s code, which can be especially useful when working on a team.
For these examples I will be implementing common designs patterns using a language I am familiar with, such as TypeScript, and then comparing and contrasting to implementing the same design pattern using a new language that I am learning, such as C#.
GitHub Code Repositories
The code for all examples can be found on GitHub:
Creational Design Patterns
Creational design patterns are design patterns that deal with object creation mechanisms, trying to create objects in a manner suitable to the situation.
The basic form of object creation could result in design problems or added complexity to the design.
Creational design patterns aim to solve this problem by somehow controlling this object’s creation.
The Simple Factory pattern is often used as an initial iteration towards more advanced patterns. It is a simple and easy to implement pattern that contains one object creational function with a conditional that uses method arguments to determine what object / class to return.