Sunday, October 27, 2013

Design Patterns in C# series

During this series I'll talk about what are design patterns, why are they important in software development, what are common uses cases, which advantages do they bring to software as well as how they are implemented in C#. In order for you to be able to fully understand the specifics of the patterns implementations I'm assuming that you're familiarized with OOP basic concepts like encapsulation, polymorphism, inheritance, abstraction, delegation among others, if you're not familiar with them here are some resources where you can find more about them: , . In this first post of the series I'll talk about a brief introduction to Design Patterns, what are they, what benefits they provide and how are they generally classified.



Now let's start by defining what a design pattern is: as a general concept a pattern is a model used as guideline for doing something; In terms of software engineering A DESIGN PATTERN IS A WELL-KNOWN REUSABLE SOLUTION TO A COMMON PROBLEM. A design pattern is not a complete solution that can be converted into code instead it provides guideline and advice on how the structure, relationships and interactions between the classes or objects should be. The use of design patterns provide benefits not only to software architects they also provide a wide range of benefits to software developers, testers and project managers, for example:




* Speed up software development by providing tested and proved paradigms



* Provide a way for understanding and solving a particular problem



* Allow developers, testers and project managers to improve communication by providing common and well-known terminology



* Promote coding reusable well tested code



* Allow project managers and developers to work under tight deadlines



* Provide developers with more readable code



Design patterns can be mainly classified in three categories Creational, Structural and Behavioral; depending the focus of the problems they are trying to solve. Let's look closer into each of the categories and find out the definition of the problem each of them tries to address:



CREATIONAL PATTERNS



This type of patterns are all about class (object) instantiation, these particular patterns are focused on separating the systems from how the objects they consume are created, composed and represented.These patterns are sub-categorized in two groups: class-creation patterns which main focus is to use inheritance properly during the instantiation process and object-creation patterns which use delegation for getting the instantiation of objects effectively done.



STRUCTURAL PATTERNS



These patterns main focus is to implement the classes and objects in an efficient way by making use of inheritance and composition. This is usually done by identifying simple ways to handle relationships between the objects.



Behavioral Patterns



This design patterns are all about class-objects communication. Behavioral patterns are focused to increase flexibility in carrying out communication between different classes-objects. These patterns are usually concerned about the assignment of responsibilities between the objects, or encapsulating behavior in an object and delegating requests and processing of it.



In the following posts of the series I'll dive into each of these three categories and the specifics of the most common patterns in each of them as well as the implementation of each pattern, I'll also provide explanation to the code and the alternatives that can be used for coding the same pattern, remember that the implementation varies from one language to another and there can even be multiple implementation of the same pattern within the same language according to the specifics of the project, I'll cover the most common scenarios hoping that these series will be useful for you and will encourage you to promote the use of patterns on your projects and ultimately making your developer life simpler.



One more thing before I move onto the next post, Design Patterns are a great and useful tool for programming, however you have to keep in mind at all times that there might not be the need to apply them to all the things you code as some of them might be simple enough to implement with a few lines, and the use of patterns might add unnecessary complexity and/or overhead. So this week I'll leave you with two quotes that will help you remember this:



If all you have is a hammer, everything looks like a nail. - Abraham Maslow



Give a small child a hammer and he will find everything needs pounding. - Abraham Kaplan
Full Post

No comments:

Post a Comment