Click here to Skip to main content
15,881,413 members
Everything / Patterns

Patterns

patterns

Great Reads

by Rahul Rajat Singh
In this article, we will try to understand what is Factory Pattern, what are the benefits of this pattern and how we can implement this pattern using C#.
by Evoluteur
A generic Web User Interface for CRUD applications generating all screens at run-time based on external metadata. It comes with sample applications for address book, memo pad, to do list, restaurants list, wine cellar, and database structure documentation that are easily customizable.
by Mark Pelf
Tutorial article on Fluent Interface Pattern in C#
by fabio bussu
MatchKit is a .NET Library that provides a set of classes to build patterns to match simple and complex strings

Latest Articles

by Dev Leader
Learn how to use Polly in C# to handle faults and retries with ease! Check out three code examples showcasing different use cases of Polly in C#!
by Dev Leader
Learn what the Command Pattern in C# is and the design principles it follows. Understand the pros and cons!
by Stridemann
Example of use of this pattern in game development
by Stridemann
A Pattern for Identifying Processed Entities During Iteration Without Additional Collections

All Articles

Sort by Score

Patterns 

9 Feb 2015 by Rahul Rajat Singh
In this article, we will try to understand what is Factory Pattern, what are the benefits of this pattern and how we can implement this pattern using C#.
11 Jun 2010 by Evoluteur
A generic Web User Interface for CRUD applications generating all screens at run-time based on external metadata. It comes with sample applications for address book, memo pad, to do list, restaurants list, wine cellar, and database structure documentation that are easily customizable.
5 Mar 2022 by Mark Pelf
Tutorial article on Fluent Interface Pattern in C#
21 Apr 2014 by fabio bussu
MatchKit is a .NET Library that provides a set of classes to build patterns to match simple and complex strings
20 Jan 2016 by Rahul Rajat Singh
This article is yet another explanation and implementation of the singleton pattern.
11 Oct 2011 by Enrique Albert
Baseline WCF Distribution Layer - Decoupling of WCF Services and ViewModels.
26 Feb 2015 by Giovanni Scerra
Patterns to prevent null reference exceptions
2 May 2015 by Giovanni Scerra
An introduction to transparency in software design, with particular focus on OO languages
11 Nov 2018 by Christian Vos
SOLID principles: The Liskov Principle, a simple example in C#
23 Apr 2013 by Jon Woo
I am writing this article to demonstrate how to build an application from scratch using SOLID principles and common design patterns
9 May 2022 by Mark Pelf
In this article, we build a practical reusable Logging Proxy in C#
9 Jul 2011 by Paulo Zemek
The easiest singleton pattern is the one you used to the lock object itself.Creating any variable as static readonly and initializing it directly (or via a static constructor) will already make it singleton.Also, considering that "lock" clears all the caches, you don't need to declare the...
13 Jul 2022 by Mark Pelf
Beginner’s tutorial on Service Locator Pattern with examples
11 Sep 2022 by Mark Pelf
Tutorial article on Observer pattern in C#
28 Feb 2022 by Mark Pelf
Tutorial article describing Visitor Pattern in C#
14 Feb 2010 by Nicolas Dorier
A design pattern to easily bind or animate properties that do not exist on an element, and which works in both Silverlight and WPF
29 Sep 2010 by Gary H Guo
Discuss how to add aspects to object at runtime and enhance them using Dynamic Decorator
16 Jul 2015 by Shivprasad koirala
In this article, we will demonstrate Template Pattern reusing ADO.NET.
14 Nov 2013 by shijo joseph
An extension methods library which could do the equality comparison operations easily
19 Mar 2014 by David Cantrell
In which a class that wraps an ADO Connection object and makes it more developer-friendly is discussed.
6 Sep 2013 by Ryszard Dżegan
How to not damage yourself when using inheritance.
5 Aug 2014 by Chris875
State pattern and procedural solution illustrated
16 Sep 2014 by Gediminas Geigalas
In your domain model, you often need to pass the same repetitive information to your domain entities or value objects. This article suggests a solution that I call "Domain Context".
2 Jun 2020 by Kevin Mack
Few ideas for strengthening micro-services architectures
8 Oct 2015 by Anele 'Mashy' Mbanga
A look at a flexible Java MySQL CRUD PHP script generator
5 Apr 2023 by Kenji Elzerman
C# decorator pattern allows adding behavior to objects at runtime. In this tutorial, I show you how to implement the decorator pattern with C# in a minimal API.
29 Aug 2022 by Aleksandr Ulanov
What are Service Objects and how you can use them to make your app cleaner and keep it maintainable
14 Mar 2011 by Tarun.K.S
That's possible using a Singleton Class.Check this link : http://csharpindepth.com/Articles/General/Singleton.aspx[^]The author provided a nice and elegant explanation to implement it, its thread safe too. Hope it helped! :)
14 Mar 2011 by Sandeep Mewara
Okay. Did you come across class the design pattern called Singleton class yet?Here:http://msdn.microsoft.com/en-us/library/ff650316.aspx[^]http://msdn.microsoft.com/en-us/library/ee817670.aspx[^]
14 Mar 2011 by Manfred Rudolf Bihy
Please see my solution to this question here: how to open only one instance of class not more than that ?[^]. Eventhough it's for a windows form class the same principles apply for other classes too.As Sandeep already pointed out there is a design pattern called Singleton, which will solve...
15 Mar 2011 by Espen Harlinn
Take a look at the Lazy Class[^] - it provides an implementation of the singleton pattern.Your implementation contains a small bug - you need to make getInstance() static too. The will enable you to get the single instance of OnlyOne using OnlyOne obj = OnlyOne::getInstance();private...
14 Mar 2011 by TweakBird
Hi Go through this design_patterns[^], You will good idea. Very good one for beginners.[Update]Similar discussion on stackoverflow.com,When to use the singleton[^]When to use factory methods?[^]Some other articles,Pattern Singleton[^]Pattern Factory[^]
15 Mar 2011 by Espen Harlinn
Here is a Lazy :)System.Lazy[^]Implements the singleton pattern in .Net ...Best regardsEspen Harlinn
31 Jul 2011 by Keith Barrow
No they aren't the same, though they do have similarities. Formally, in a 3-tier system, there is no communication between the data tier and the ui/presentation tier, both must communicate with the logic/model tier/ The topology is layered:Presentation / GUI------------------Logic /...
24 Nov 2011 by Scanix
SystemFramework defines interfaces, classes, and types to support a native runtime system with its own garbage collector, delegates, etc. The design of SystemFramework classes is similar to those of the .NET Framework.
6 Dec 2011 by Sergey Alexandrovich Kryukov
The solution cannot be universal because everything depends on the nature of changing requirements. Resorting to extensions as opposed to modification cannot really help.I can see only one way: to change approach from hard-coded structures to stored meta-data and knowledge engineering, in...
2 Aug 2013 by Dev Leader
About dependency injected singletons
11 Oct 2013 by ASP.NET Community
MVP (Model View Presenter) FrameworkThe MVP pattern is an Architecture Pattern used to build ASP.net applications.  It refers to splitting up the
29 Dec 2013 by pasztorpisti
You can create a good interface that is a common denominator of many other APIs only if already know the other APIs and the intersection of their functionalities. Often the good solution is not a bloated wanna-be-smart and generalized interface but one that contains only a few simple-stupid...
29 Dec 2013 by Sergey Alexandrovich Kryukov
Please see my comment to the question. I strongly believe that the project should not be driven by design patterns, but your project should drive the choice of design patterns. Sorry if this advice is not specific enough, but it is no less specific than your description of the goals of your...
11 May 2015 by Sascha Lefèvre
You can't have methods in the same class that only differ by their return type.I can think of two ways for code-reuse here, both requiring making Execute(..) a generic method.1) If you can replace Func1 and Func2 by a generic Func :public T Execute(object parameters){ ...
6 Nov 2015 by Sergey Alexandrovich Kryukov
There are absolutely no any cookbook recipes to be used to identify design problems. Perhaps except one: take the whole problem to be solved from scratch and try to sketch some best designs you can invent. If your plan looks much better than existing design, that existing design flawed. But be...
7 Feb 2023 by Mark Pelf
Beginner’s tutorial on VO and DTO Patterns with examples
14 Mar 2011 by Sergey Alexandrovich Kryukov
The Question in not completely incorrect, but can be greatly improved. You should have re-formulated it:"How to use Wikipedia, Google, CodeProject and StackOverflow.com?"If you asked and got good Answers, the Questions like your original one would not be needed!—SA
31 May 2011 by Sergey Alexandrovich Kryukov
In addition to what Abhinav says: it totally depends on your functional requirements.No design pattern is good by itself.Three-tiers architecture is not considered a design pattern or architectural pattern, as it's more of application architecture, and design patterns are more...
7 Oct 2011 by Sander Rossel
With the strategy pattern it is possible to change or extend the behaviour of a Class.This sounds a bit abstract, but let's look at an example.public interface IMathOperation{ double PerformOperation(double A, double B);}class DoMath{ private double _A; private...
7 Nov 2011 by Henry.Ayoola
Jon Skeet has written an article giving six singleton implementations in C#. The simplest only works in .NET 4:public sealed class Singleton{ private static readonly Lazy lazy = new Lazy(() => new Singleton()); public static Singleton Instance {...
18 Jan 2012 by Sergey Alexandrovich Kryukov
Wikipedia is on a blackout for a really good reason at this moment, in response to SOPA and PIPA bills. Please see:http://en.wikipedia.org/wiki/Main_Page[^], http://en.wikipedia.org/wiki/Wikipedia:SOPA_initiative/Learn_more[^].It will be available soon. Hope it will be fine in future as...
11 Oct 2013 by ASP.NET Community
Design PatternsDesign patterns are recognized solutions to common problems defined originally by the Gang of Four programmers. Design patterns are
20 Oct 2013 by Sergey Alexandrovich Kryukov
I think, in your speculations on the classes, interfaces and methods you already limited yourself to some unreasonably rigid set of possible type designs. You need to take a wider look.I can see two approaches.First one would be this: you have one and only one color class. This and only...
2 Feb 2015 by Chris_Yu
Why and When to Use the Adapter Pattern in PHP Development
22 Dec 2015 by Richard Deeming
Your parameters are the wrong way round - the first parameter is the string to test, and the second parameter is the regular expression to use:Regex.IsMatch(myString, ".* My name is XYZ")To retrieve the details of the match, use the Match method[^], which returns a Match object[^]....
4 Aug 2016 by Patrice T
This is HomeWork, so only advices.The pattern is:Pascal's triangle - Wikipedia, the free encyclopedia[^]-try to solve the problem as 2 problems: - solve the computing of each rows values. - Solve the presentationyou need to remember the previous row to compute the next one.Nota:...
13 Oct 2016 by Rahul Rajat Singh
This is a small tip containing my thoughts on why we should not blindly create interfaces and/or abstract class for each and every class in our application.
14 Mar 2011 by Albin Abel
E$w@r's link is a good one. In a nutshell Singletons are generally used prevent repeated load of a heavy resource in memory. Say class A has a big common dataset which is reusable. If many other objects access various instance of this object then it is a wastage of memory, because the same type...
17 Oct 2011 by NewPast
Dim pattern="http.*\.flv"Dim pattern2="^http.*\.flv$"'^ means at the 1st of the line; $ means at the end of the line
23 Jan 2012 by malakar.anil
This article explains how to write easily maintainable and extendable application using MVC
13 May 2012 by Clifford Nelson
Acutally made error in putting the "-" inside the Math.Pow(-(x1 - Math.PI), 2), and the approach is not the best. I would also not use the Pow for square because of perfomance, and would use the Exp function:var VALUE = - Math.Cos(x1) * Math.Cos(x2) * Math.Exp(-(x1 -nu) *(x1 - Math.PI) -(x2...
28 Jun 2012 by email2gtc
I am creating an application to recognize books by its spine. What I want to do is take picture of a book spine and match it with a database of books.I was hoping to use pattern matching and template matching for this. First i was hoping to search book by template matching using templats of...
1 Aug 2012 by Christian Graus
If you're not using the MVC framework, then how are you using MVC ? You can write a login page in ASP.NET without using MVC, but you can't easily use the MVC pattern in ASP.NET if you don't use the framework, the restraints of the ASP.NET framework make it harder to impliment an arbitrary design...
9 Dec 2012 by Sergey Alexandrovich Kryukov
You need to look at Data Contract. Please see:http://msdn.microsoft.com/en-us/library/ms733127.aspx[^].Please see my past answer where I explain it:How can I utilize XML File streamwriter and reader in my form application?[^],Creating property files...[^].—SA
12 Dec 2012 by Sergey Alexandrovich Kryukov
Please see my comments on persistence. If should be either Data Contract or something like that. It should be agnostic to UML. As soon as your persistence start depending on UML definitions or anything of application field, consider all your development dead. And it should be no XAML, because...
12 Dec 2012 by Sergey Alexandrovich Kryukov
OK, I'll show some very rough sketch of UML hierarchy. Very preliminary, pseudo-code, and only for Class Diagram and top level. Perhaps you well see that you might under-estimate the task.Let's start with abstract top level of hierarchy: abstract class Element { // Name:...
20 Feb 2013 by Joezer BH
Try this:string regexSearch = new string(Path.GetInvalidFileNameChars()) + new string(Path.GetInvalidPathChars());Regex r = new Regex(string.Format("[{0}]", Regex.Escape(regexSearch)));Cheers, Edo
22 Mar 2013 by OriginalGriff
Google is your friend: Be nice and visit him often. He can answer questions a lot more quickly than posting them here...A very quick search using part of your question as the search term gave : 1.6 million hits.when to use singleton pattern[^]In future, please try to do at least...
19 May 2013 by Yossi Yaari
A basic yet generic state machine implementation
9 Aug 2013 by Dev Leader
In this post, I’m going to focus on why singletons are “bad”, because for me it means acknowledging one of the two main perspectives–that they are the best thing since cat videos met The Internet or they are the worst thing since Justin Bieber.
10 Sep 2013 by TheUltimateDebugger
As far my knowledge so farRepository Pattern With Entity Framework[^]
25 Sep 2013 by OriginalGriff
The biggest difference (indeed in code terms pretty much the only difference) is that a Singleton class does not have a public constructor: you have to go via the class GetInstance method (or similar) in order to create an instance as the outside world is not allowed to use:MySingletonClass...
14 Jan 2014 by ASP.NET Community
The visitor design pattern enables us to create new operations to be performed on an existing structure. The new operations don’t change the
19 Oct 2013 by ASP.NET Community
The iterator pattern’s role is to provide a way to access aggregate objects sequentially without the knowledge of the structure of the aggregate.
12 Dec 2013 by Tadit Dash (ତଡିତ୍ କୁମାର ଦାଶ)
I would suggest you to have two Tables.1. Users2. RoleThese tables should have a Relationship through the RoleId. That means RoleId will be ForeignKey in Users Table.For instance...UsersID Name RoleId1 Abc 12 Def 2RoleID Name1 ...
11 May 2015 by BillWoodruff
Here's an example of a static generic Class that will return instances of new Classes where the internal data type used by the new Class is constrained to be a struct. I believe this example demonstrates the "usual" features of implementing the Factory Class pattern in C#: use of an interface;...
25 Apr 2018 by OriginalGriff
The idea of a singleton is very simple: it's a class with a private constructor, so it cannot be instantiated form outside the class. This means that the class is absolutely in control of how many instances of the class are created, and when they are created. A singleton class creates a single...
25 Apr 2018 by CPallini
I would start form its very Wikipedia page: Singleton pattern - Wikipedia[^].
31 Aug 2018 by Peter Leow
Try this: ^[0-9]$|^1[0-2]$ for the first one. You should be able to figure out the other one. The 30 Minute Regex Tutorial[^]
22 Nov 2019 by Jeremy Likness
Stateful serverless: long running workflows with durable functions
12 Mar 2020 by Kevin Mack
What kinds of things should I avoid, or remove from my applications to improve my position moving forward
6 Feb 2023 by Mark Pelf
Basic tutorial on Immutable Object Pattern along with C# examples
18 Dec 2023 by M Imran Ansari
As the error message, the issue is in Delete method. The Delete method attempts to remove an entity from the context using LapShopContext.Set().Remove(entity). However, the error you're encountering is a NullReferenceException, which suggests...
11 Dec 2023 by Stridemann
Example of use of this pattern in game development
12 Mar 2024 by Dev Leader
Learn how to use Polly in C# to handle faults and retries with ease! Check out three code examples showcasing different use cases of Polly in C#!
7 Feb 2010 by Samer Aburabie
I am not sure if I understood you well, but you mixed things up here, you are talking about a communication protocol like TCP/IP or UDP and in the same time you want to implement it with a design pattern !?!! I think your worries should be bigger than that.
21 Feb 2011 by jim lahey
I would assume that because the new members you propose to add are members of a singleton object, that they will in fact also be singletons by means of association. in a traditional singleton pattern you access the only instance via the static .Instance member which can have a double locking...
14 Mar 2011 by OriginalGriff
You are looking for a regular expression. This is what Expresso came up with:' Imports System.Text.RegularExpressions' Regular expression built for Visual Basic on: Mon, Mar 14, 2011, 01:42:46 PM' Using Expresso Version: 3.0.3634, http://www.ultrapico.com'' A description of the...
27 Mar 2011 by #realJSOP
Pick the one that gets the job done, or don't pick one at all. I've never consciously made a decision to use a specific "design pattern". I do what makes sense for the project, and get on with my life. I usually split the interface as much as possible from everything else, and go with it. If...
29 May 2011 by Sandeep Mewara
Here:MSDN: Singleton Implementation[^]MSDN: Exploring Singleton Design Pattern[^]Singleton design pattern: Thread-safe Singleton[^]Implementing the Singleton Pattern in C#[^]This answer and others to the same question would also help: About Design Patterns Singleton and Factory[^]
31 May 2011 by BobJanova
In addition to the excellent links already posted:Architecture is a somewhat nebulous concept, but relates to high level design decisions, and things which become expensive to change later on. The '3 tier' architecture is traditional for web applications and it works well (though one might...
31 Jul 2011 by Uday P.Singh
Hi guys!!I have read a lot about both, but still confused. Does MVC and 3-Tier both are same? If yes then why these two exists, just for different naming? If no then what are the basic and main differences in these two?Please Reply(No extra links Please as I have already googled it but...
10 Sep 2011 by Dennis Th
Hidid you try gang of fours' homepage ?they have a lot of tutorialsDennis
10 Sep 2011 by Pravin Patil, Mumbai
Check out : 1. Non Software Examples and Case Studies[^]2. From Experts - Design Patterns Explained with Practical Examples[^]Hope this helps.All the best.
7 Oct 2011 by EgyptianRobot
need someone professional help me get the difference beteenfirst : static class SimpleMathOperations { public static double add(double a, double b) { return a + b; } public static double subtract(double a, double b) { return a - b; } public...
15 Oct 2011 by Espen Harlinn
Take a look at these pages Microsoft Dynamics CRM SDK[^] - A web service, as in Web Service Walkthroughs[^] is probably your best choice - think in terms of operations, and only expose what is strictly required."Moreover,will there be any need of load balancing (web farm ) for 6000 to 7000...
6 Dec 2011 by kkadir
Hello,It is a common problem that during an ongoing project requirements do change frequently. Functional changes can be handled using -for instance- the decorator pattern and so on. But a serious problem is that when the static structure of any entity changes. You have to do relentless...
24 Feb 2012 by Sander Rossel
Actually I don't think this should be a problem. If you are using a singleton pattern you are probably calling a shared method that initializes your object. Even though the object is created on a certain thread this should not prevent it from being accessed from others (unless it's some UI...
9 Apr 2012 by Rahul Rajat Singh
3 tier application development can be understood by following examples.YaBlogEngine - A Tiny Blog Engine written in ASP.NET/C#[^]YaMessaging - A simple e-mail like messaging application[^]and use of design patterns depends more on the business logic need and overall architecture....
22 Jun 2012 by A. Ganzer
Using snippets to create a full and correct implementation of complex interfaces
28 Jun 2012 by krumia
You have done well to use histograms to identify similar images. You will have to use pattern recognition[^] to do the rest.Try separate algorithms for cropping, rotating and scaling the image. For example when a photo of a book spine is provided,1. You first rotate it such that the spine...