Click here to Skip to main content
15,890,123 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 Updated

Patterns 

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#!
15 Feb 2024 by Dev Leader
Learn what the Command Pattern in C# is and the design principles it follows. Understand the pros and cons!
19 Dec 2023 by Richard Deeming
Since your repository code is swallowing all exceptions - an extremely bad idea, by the way! - the only reason for a NullReferenceException would be that the baseRepository is null. Check the constructor to make sure you've assigned the field...
18 Dec 2023 by A Belal
in Repository Pattern System.NullReferenceException Delete Method System.NullReferenceException HResult=0x80004003 Message=Object reference not set to an instance of an object. Source=Microsoft.EntityFrameworkCore StackTrace: at...
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
9 Dec 2023 by Stridemann
A Pattern for Identifying Processed Entities During Iteration Without Additional Collections
21 Sep 2023 by ashish__shukla
MediatR Library provides a simple way of implementing mediator pattern in .NET applications.
20 Sep 2023 by ashish__shukla
Understanding CQRS pattern at a high level
13 May 2023 by Member 14952571
Print the following pattern in python for the given number of rows. Pattern for N = 5 1 2 3 4 5 11 12 13 14 15 21 22 23 24 25 16 17 18 19 20 6 7 8 9 10 What I have tried: n = int(input()) upper =...
13 May 2023 by Member 16003557
n = int(input()) if n%2 == 0: m = n//2 else: m = n//2+1 for i in range(1, m+1, 1): for j in range(1, n+1, 1): print(2*n*(i-1)+j, end ='') print(' ',end = '') print() r = n - m for i in range(r, 0, -1): ...
22 Apr 2023 by Coral Kashri
How to implement a compile-time Decorator
22 Apr 2023 by Coral Kashri
How to correctly implement design patterns in C++
22 Apr 2023 by Coral Kashri
RunTime Reflection in C++
22 Apr 2023 by Coral Kashri
Involves usage example of shared_ptr aliasing constructor, design patterns reflection and factory, metaprogramming, string_view and variant/visit.
20 Apr 2023 by Kenji Elzerman
Learn how to use the strategy pattern in C# to create flexible and reusable code. Replace if-statements and simplify your code with this design pattern.
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.
7 Feb 2023 by Mark Pelf
Beginner’s tutorial on VO and DTO Patterns with examples
6 Feb 2023 by Mark Pelf
Basic tutorial on Immutable Object Pattern along with C# examples
21 Jan 2023 by Member 15901317
n = int(input()) if n % 2 == 0: n1 = int(n/2) n2 = n-n1 else: n1 = int(n/2)+1 n2 = n-n1 x = 1 i = 1 i1 = 1 #Upper pattern while i
11 Oct 2022 by Maciej Los
Sorry, but your question is not clear... Seems you want to find a substring within a title... Regex is not for such of requirements. If you want to get a text within a "group-title=", try this: .group-title=\"(.*?)\" Example: regex101: build,...
10 Oct 2022 by Jake-J
Hi there, I'm new to regular expression and I'm trying to learn it. I have a string like this: #EXTINF:-1, tvg-name="THE NAME" tvg-logo="THE LOGO" group-title="THE TITLE",THE ITEM https://www.SampleSite.com I'm going to check if THE TITLE part...
11 Sep 2022 by Mark Pelf
Tutorial article on Observer pattern in C#
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
9 Aug 2022 by Mark Pelf
We explain DI Pattern, DIP, IoC, DI Container
13 Jul 2022 by Mark Pelf
Beginner’s tutorial on Service Locator Pattern with examples
24 Jun 2022 by x_cud_x
n = int(input( )) P = 1 for i in range(1, n + 1): for j in range(P, P + n): print(j, end=" ") print() if i == ((n + 1)//2): if (n % 2) != 0: P = n*(n - 2) + 1 else: P = n * (n - 1) + 1 ...
22 May 2022 by Phoenix Liveon
A quick quest: We want the result looks like this; from aaa---bbb-ccc into aaa.bbb.ccc What I have tried: def objective = "aaa---bbb-ccc" objective.replace(/.*[-]+.*/, '.') How do we create a proper pattern of Regular expression in Groovy?
9 May 2022 by Mark Pelf
In this article, we build a practical reusable Logging Proxy in C#
15 Apr 2022 by Phoenix Liveon
I found some answer and this is what its looks like we substitute method "replace" with "replaceALL"; def objective = "aaa---bbb-c" println( objective.replaceAll(/[-]+/, '.') )
15 Apr 2022 by OriginalGriff
That's because you don't use the "non-hyphen" data in your replacement. Try this: (.*?)-+(.+?)-(.*) And this replacement string: $1.$2.$3
15 Apr 2022 by Patrice T
Did you tried this ? def objective = "aaa---bbb-ccc" objective.replace(/[-]+/, '.') Just a few interesting links to help building and debugging RegEx. Here is a link to RegEx documentation: perlre - perldoc.perl.org[^] Here is links to tools...
1 Apr 2022 by Mark Pelf
Tutorial on Decorator Pattern in C#, showing 3 versions in C#
25 Mar 2022 by raki you
* * ** ** *** *** **** **** ********** What I have tried: I have tried so hard but couldnt do it, please help me
25 Mar 2022 by OriginalGriff
While we are more than willing to help those that are stuck, that doesn't mean that we are here to do it all for you! We can't do all the work, you are either getting paid for this, or it's part of your grades and it wouldn't be at all fair for...
5 Mar 2022 by Mark Pelf
Tutorial article on Fluent Interface Pattern in C#
28 Feb 2022 by Mark Pelf
Tutorial article describing Visitor Pattern in C#
12 Feb 2022 by Gerry Schmitz
I think the interface definitions are part of the problem: IConfigurable is missing a "Name" in this context. And IConfigurable maybe should inherit IReadOnly instead. .net - Should one interface inherit another interface - Stack Overflow[^] On...
12 Feb 2022 by C Pottinger
I have a class that I would like to present in two different ways: as an item that can be manipulated and configured by the user, and as an item that can only be displayed. In the example below I am using a shape that can be either drawn and...
12 Feb 2022 by #realJSOP
I would simply add a bool parameter to the constructor (and an associated property) that defaults to the most-used value, and then change the desired properties to do nothing in the set method if the object is specied as read only.
26 Jan 2022 by John1990PL
I would like to know if there is an algorithm that could help me solve the following example problem. First off we have a list of 1 and 0: 011001010111 of length 12. Then we have an x number of 1 to inject anywhere in the list, for instance x=3...
26 Jan 2022 by Patrice T
Quote: I would like to know if there is an algorithm that could help me solve the following example problem. This problem is furiously looking like a problem from a challenge site. For this kind of problem, the solution is never simple minded or...
27 Dec 2021 by Member 15481083
The more optimized version will be: n = 5 h = 0 d = int(n/2)+1 for r in range(0, n): s='' if r
27 Aug 2021 by Giovanni Scerra
Strategies and heuristics of Problem Solving applied to Software Engineering
30 Jul 2021 by Atul Shreewastav
1 6 10 13 15 2 7 11 14 3 8 12 4 9 5 This is how the output should look like What I have tried: I tried to find a specific pattern that follows in the rows and columns and found: 1....
30 Jul 2021 by OriginalGriff
Think of it this way: assuming you have to print this in a console, then you need to print it as complete rows (or it gets complex: you need to create a 2D array, fill it, and then print that. While that is actually pretty simple to to, if you...
19 Jul 2021 by Member 15294621
There are several articles out there. But as Dave mentioned, you need to go through one by one & see what works for you. Anyways, I think KMP Algorithm Explained In Plain English[^] can help you out. It doesn't have technical jargons & use...
19 Jul 2021 by Member 15294496
I am trying to understand Knuth–Morris-Pratt or KMP algorithm for text searching. But I find it very difficult to understand especially the time complexity. If you guys are aware of some easy to understand tutorial, please help me out. Thanks. ...
19 Jul 2021 by Patrice T
Quote: I am trying to understand Knuth–Morris-Pratt or KMP algorithm for text searching. The algorithm is mostly a black box to you, get sample code and use the debugger to open that box, you will see how the code deals with an input. There is...
19 Jul 2021 by Dave Kreskowiak
Well, there's a problem with your question. What is easy for someone else to understand may not be easy for YOU to understand. So there's really no answer to your question other than YOU going through Google and reading source after source until...
19 Jul 2021 by Richard MacCutchan
Knuth–Morris–Pratt algorithm - Wikipedia[^]
21 Oct 2020 by Patrick Skelton
Apologies for the vague nature of the question. I couldn't think of a concise way to explain the problem I seem to be facing for the Nth time and which I think must be an extremely common scenario. Code explains it best... abstract class...
21 Oct 2020 by F-ES Sitecore
Try something like public abstract class GraphicsBase where T : LogicBase { public GraphicsBase(T logicObject) => StronglyTypedLogicObject = logicObject; public LogicBase LogicObject => StronglyTypedLogicObject; public virtual T...
30 Sep 2020 by Maciej Los
Try this: n = 5 h = 0 d = int(n/2)+1 for r in range(0, n): s='' for c in range(1, n+1): if r
20 Jul 2020 by Arlo Weston
Implementation of the Chain of Responsibility Pattern in JavaScript
23 Jun 2020 by Ciumac Sergiu
Explains sound fingerprinting algorithm, with a practical example of detecting duplicate files on the user's local drive.
2 Jun 2020 by Kevin Mack
Few ideas for strengthening micro-services architectures
21 May 2020 by Vlad Neculai Vizitiu
Null-object pattern in C# 8
15 May 2020 by Rion Williams
Some recommended readings about streaming systems
13 May 2020 by Richard MacCutchan
complete local ternary patterns - Google Search[^]
11 May 2020 by Daniele Fontani
Learn how to configure dependency injection to make things happen by design
12 Mar 2020 by Kevin Mack
What kinds of things should I avoid, or remove from my applications to improve my position moving forward
31 Jan 2020 by honey the codewitch
Add fast scanners/tokenizers to your C# project
22 Nov 2019 by Jeremy Likness
Stateful serverless: long running workflows with durable functions
21 Nov 2019 by Jeremy Likness
Learn how durable entities provide explicit management of state in serverless applications and guarantee operations are safe to execute without concurrency conflicts.
3 Apr 2019 by Mahsa Hassankashi
This is the simplest tutorial on AngularJS and Repository Pattern for developing professional MVC applications. It includes a source code about practical permission management project.
6 Jan 2019 by blueshabat
Hi, I want to use the microservices pattern in a complex system. The thing is that I have some methods that I'll use in many microservices, GetAccounts for example. Would I have to implement that method in each microservice? What would be the best way to perform this? What I have tried: I have...
6 Jan 2019 by Aydin Homay
First of all, Microservices is not a pattern is a software architecture in the SOA field. This is very imprtant to understand. Unlike SOA, Microservices Architecture (MSA) tries to share as less as possible, means that do not share any common functionalities between microservices and make them...
13 Dec 2018 by RickZeeland
Maybe this will be of help: Factory Method Pattern vs. Abstract Factory Pattern[^] If you want to learn about other patterns from the original "Gang of four" then DZone has a nice refcard about it (you will need to sign in, it's free): https://dzone.com/refcardz/design-patterns?chapter=1[^]
13 Dec 2018 by Ashishmau
Suppose, I have four different entities in our c# design system. 1. Organization 2. Class 3. Course 4. Students Now, I have to pull the above entities data from the third party API and store in our system. I have created the four different business access classes of above entities which...
8 Dec 2018 by RickZeeland
DZone has a nice refcard about the original Gang of Four design patterns which you can download for free (after signing up): https://dzone.com/refcardz/design-patterns?chapter=1[^] I also stumbled upon this article on DZone about the Factory pattern by a well known CodeProjector (Richard...
6 Dec 2018 by CursedProgrammer
I am currently working on a bigger WinForms project. I used to program small applications using WinForms that had a maximum of ~20 different windows. Now I am facing a bigger project and want to adapt to that by overthinking my approach to that. I have read about MVVM and MVC and some...
6 Dec 2018 by RickZeeland
Maybe you can use custom forms, something like this: public class CustomForm : Form { /// /// Initializes a new instance of the class. /// public CustomForm() { // Required for Windows Form...
27 Nov 2018 by Member 12598972
Below is the code in Javascript: const printNumberStarMatrix = function (row, col) { for (let i = 1; i = 1; --j) { strToPrint = j + strToPrint; } while (strToPrint.length
27 Nov 2018 by OriginalGriff
Do these two lines do exactly the same thing? while (strToPrint.length
18 Nov 2018 by kubibay
We are using repository pattern in our mvc project. But I'm unable to implement service in quartz jobs. Here is the code; [DisallowConcurrentExecution] public class DeleteContentsJob : IJob { private readonly IAttachmentService attachmentService; public...
11 Nov 2018 by Christian Vos
SOLID principles: The Liskov Principle, a simple example in C#
1 Oct 2018 by Member 14001894
im using spring therefore i choose zuul ( https://spring.io/guides/gs/routing-and-filtering/ )
29 Sep 2018 by Member 14001894
Halli Hallo i hope im at the right Place. I want to get started with API-Gateway(s). Currently im running 5 Microservices written in Java (Spring-Boot) deployed via Docker. Each Microservices is protected via Keycloak. I want to use a API-Gateway so that i can combine every MS into 1 Link: ...
20 Sep 2018 by VarunSharma43
Hi Friends, I am developing a translation tool. First I want the develop a glossary from existing translations so I developed a GUI which has 2 panes. left side has english and right side has hindi. For hindi its easy to find a new line using '|' however for english its a bit challenge since ....
10 Sep 2018 by Member 13979315
I am a relative beginner to programming. I want to take what I have learned and create a simple inventory system, more specifically an asset management system that could track IT hardware types (laptop, workstation, monitor, etc) and then assign values to it. I don't think this should be too...
10 Sep 2018 by Afzaal Ahmad Zeeshan
Short answer: Do whatever you want to, just don't over engineer the software, that is becomes a mess to manage and less useful. The first thing I would ask myself is, who is going to use the software? A consumer on his own machine, or a bunch of users consuming the API, or my web app? So the...
31 Aug 2018 by David Crow
Rather than use a regular expression, have you considered calling setFilters() on the EditText object? Something like: EditText et = (EditText) findViewById(R.id.edit1); et.setFilters(new InputFilter[]{ new InputFilterRange("0", "12")}); ... et.setFilters(new InputFilter[]{ new...
31 Aug 2018 by Member 12663465
I want to regular expression patter for Numbers i have a form in which there are two textbox textbox1 , textbox2 textbox1 should accept value between 0 to 12 only and textbox2 should accept value between 30 to 300 only i have this pattern tried not working pls help by providing the patterns...
31 Aug 2018 by Patrice T
Quote: ([0-9][2]|{1,12})$ i have tried this expression not working The first problem here is that {1,12} in your RegEx means nothing, it is not legal in this context. Second problem, your RegExs is missing ^ at beginning, which mean that any thing that ends with what you want will match. ex:...
31 Aug 2018 by Jochen Arndt
You have to parse the inputs from left to right for all possible numbers of digits. For 0 to 12 this would be 0 to 9 and 10 to 12. So a possible regex might be ([0-9])|(1[0-2]) For 30 to 300 with 30 to 99, 100 to 299, and 300: ([3-9][0-9])|([1-2][0-9][0-9])|(300) However, when using this in a...
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[^]
20 May 2018 by Vishal Wadhwa
Best way would be to define your context and domains, and use these kind of methods as service API to fetch common data from a specific microservice instead of repeating the same code everywhere. In your example of getAccount, you must have a microservice which manages accounts and getAccount...
25 Apr 2018 by CPallini
I would start form its very Wikipedia page: Singleton pattern - Wikipedia[^].
25 Apr 2018 by Prashanth Shridharchar
Hi all, i'm new to Singleton design pattern, if can ANYONE EXPLAINS or quick understanding of what is Singleton design pattern and how should i use for simple web application or anything. What I have tried: Tried with ONLINE EXAMPLE but did not understood
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...
7 Apr 2018 by Richard MacCutchan
See generic repository concrete repository - Google Search[^]
7 Apr 2018 by Dinesh Singh Kushwaha (Dev)
I have seen many programmer say that generic repository is best many programmer say concrete repository is the best. What i feel concrete repository is the best because it is more readable , maintainable and easy to understand than generic repository although we have to write more code to...
14 Mar 2018 by Sni.DelWoods
Great nested class solution: I don't have to care about the Dataset - it referes perfect to the base class. So from the sub classes I have full access to all methods of the base and It's splited into functional groups. My solution Public Class MyBigClass Public MyData As New DataSet ...
14 Mar 2018 by Sni.DelWoods
Is there a way to split a big class into sub "modules" (or something). The class has global DataSet and many methods which access or modifies the DataSet. Origin class (pseudo) Public Class MyBigClass() Public myData As New DataSet() Public Sub InitMyData() '...Build Dataset...
14 Mar 2018 by CPallini
See also What not to do: Anti-Patterns and the Solutions[^] (from our Sander Rossel) - The God Object section.
14 Mar 2018 by OriginalGriff
Well, you could nest the classes: Public Class MyBigClass Public Class DataAccess ... End Class Public Class CheckFunctions ... End Class ... End Class Or even nest them and use Partial to separate them into separate files: Public Partial Class MyBigClass Public...