anupavanm / csharp-design-patterns-for-humans Goto Github PK
View Code? Open in Web Editor NEWThis project forked from kamranahmedse/design-patterns-for-humans
Design Patterns for Humans™ - An ultra-simplified explanation - C# Examples
This project forked from kamranahmedse/design-patterns-for-humans
Design Patterns for Humans™ - An ultra-simplified explanation - C# Examples
At the Singleton example, get_instance()
should be GetInstance()
.
Also there is a redundant call to .ToString()
.
Strategy using example:
var sorter = new Sorter(new QuickSortStrategy());
sorter.Sort(unSortedList); // // Output : Sorting using Bubble Sort !
QuickSortStrategy - > BubbleSortStrategy
Before the Simple Factory, is this text:
The basic form of object creation could result in design problems or added complexity to the design. Creational design patterns solve this problem by somehow controlling this object creation.
While the individual subjects have some brief statement, sometimes these seem not to be either problems or (at least unreasonable) complexities. In fact, the "Door" example doesn't even present the situation that is covered in the "When to use" section of the Simple Factory description.
Suggestion: Give an example, in every one of these, of a common situation that would in fact have more problems/design issues, before presenting a solution to it.
The provided example for Singleton design pattern is not thread safe. This is the most basic implementation of the Singleton pattern. Please add the thread safe, lazy implementation.
public sealed class Singleton
{
private static readonly Lazy<Singleton> lazy =
new Lazy<Singleton>(() => new Singleton());
public static Singleton Instance { get { return lazy.Value; } }
private Singleton()
{
}
}
Below article from Jon Skeet would be helpful
http://csharpindepth.com/Articles/General/Singleton.aspx
Hi
last line of code in Prototype should print Jolly which is original.Name
instead of Dolly
For iterator pattern should be:
public IEnumerator<RadioStation> GetEnumerator()
{
//Use can switch to this internal collection if you do not want to transform
//return mStations.GetEnumerator();
//use this if you want to transform the object before rendering
foreach (var x in mStations)
{
yield return x;
}
}
IEnumerator IEnumerable.GetEnumerator()
{
return this.GetEnumerator();
}
Currently is wrong and throws StackOverflowException.
public IEnumerator<RadioStation> GetEnumerator()
{
return this.GetEnumerator();
}
IEnumerator IEnumerable.GetEnumerator()
{
//Use can switch to this internal collection if you do not want to transform
//return mStations.GetEnumerator();
//use this if you want to transform the object before rendering
foreach (var x in Stations)
{
yield return x;
}
}
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.