Skip to main content

Design Patterns

Design Pattern - Design pattern to build high quality robust applications.

            Developer have to take care to select the right pattern for the right problem. Improper usage lead to unmaintainable, complex and inefficient code.
      
      We shall take a look at how to use the well known Gang of Four (GoF) Design Patterns in C# 4.0 code. Those patterns will work well in any project that uses C# but especially in WPF, WCF, WinForms, ASP.NET projects. The GoF Design Patterns are divided into 3 categories : Creational Patterns, Structural Patterns and Behavioral Patterns. I am going to explain each GoF Design Pattern in detail and will show you examples of how to write good C# 4.0 code that implement those patterns.

Creational Pattern
  1. Abstract Factory Pattern: Create instances of classes belonging to different families
  2. Builder Pattern: Separate representation and object construction
  3. Factory Method Pattern: Create instances of derived classes
  4. Prototype Pattern: Clone or copy initialized instances
  5. Singleton Pattern: Class with only one single possible instance
Structural Pattern
  1. Adapter Pattern: Match interfaces of classes with different interfaces
  2. Bridge Pattern:: Separate implementation and object interfaces
  3. Composite: Simple and composite objects tree
  4. Decorator: Dynamically add responsibilities to objects
  5. Facade: Class that represents sub classes and subsystems
  6. Flyweight: Minimize memory usage by sharing as much data as possible with similar objects
  7. Proxy: Object that represents another object
Behavioural Pattern
  1. Chain of Responsibility: Pass requests between command and processing objects within a chain of objects
  2. Command: Encapsulate a method call as an object containing all necessary information
  3. Interpreter: Include language elements and evaluate sentences in a given language
  4. Iterator: Give sequential access to elements in a collection
  5. Mediator: Encapsulates and simplifies communication between objects
  6. Memento: Undo modifications and restore an object to its initial state
  7. Observer: Notify dependent objects of state changes
  8. State: Change object behavior depending on its state
  9. Strategy: Encapsulate algorithms within a class and make them interchangeable
  10. Template Method: Define an algorithm skeleton and delegate algorithm steps to sub classes so that they may be overridden
  11. Visitor: Add new operations to classes without modifying them
There are several other patterns such as Parallel Patterns, SOA Patterns, Enterprise Architecture Patterns, etc… So if we work in the respective area don’t hesitate to look up patterns that may help you to be more efficient and build better applications.

Comments

Popular posts from this blog

Python Multi Threading

Speeding up Python code using multithreading A lot of times we end up writing code in Python which does remote requests or reads multiple files or does processing on some data. And in a lot of those cases I have seen programmers using a simple  for loop  which takes forever to finish executing. For example: import requests from time import time  url_list = [     "https://via.placeholder.com/400",     "https://via.placeholder.com/410",     "https://via.placeholder.com/420",     "https://via.placeholder.com/430",     "https://via.placeholder.com/440",     "https://via.placeholder.com/450",     "https://via.placeholder.com/460",     "https://via.placeholder.com/470",     "https://via.placeholder.com/480",     "https://via.placeholder.com/490",     "https://via.placeholder.com/500",     "https://via.placeholder.com/510...

How to encrypt connection string in web.config . In order to not expose connection string to outside world.

Protecting Connection Strings and Other Configuration Information  (C#) Introduction Configuration information for ASP.NET applications is commonly stored in an XML file named  Web.config . Over the course of these tutorials we have updated the  Web.config  a handful of times. When creating the  Northwind  Typed DataSet in the  first tutorial , for example, connection string information was automatically added to  Web.config  in the  <connectionStrings>  section. Later, in the  Master Pages and Site Navigation  tutorial, we manually updated Web.config , adding a  <pages>  element indicating that all of the ASP.NET pages in our project should use the DataWebControls  Theme. Since  Web.config  may contain sensitive data such as connection strings, it is important that the contents of Web.config  be kept safe and hidden from unauthorized viewers. By default, any HTTP re...

Books To Refer

1. C#   in Depth ,  Third   Edition : Foreword   by Eric   Lippert        By:  Jon Skeet    Publication Date:  16-SEP-2013 2. Learning jQuery - Fourth Edition     B y:  Jonathan Chaffer; Karl Swedberg     Pub. Date:  June 25, 2013      3.Beginning JSON                    By:  Ben Smith     Publication Date:  04-MAR-2014 4. Responsive Web Design with jQuery     By:  Gilberto Crespo      Pub. Date:  November 25, 2013 5. Developing Responsive Web Applications with AJAX and jQuery       By:  Sandeep Kumar Patel  P ub. Date:  July 25, 2014 6. Dependency Injection in .NET     by  Mark Seemann