Code Monkey home page Code Monkey logo

anupavanm / csharp-design-patterns-for-humans Goto Github PK

View Code? Open in Web Editor NEW

This project forked from kamranahmedse/design-patterns-for-humans

1.3K 42.0 164.0 179 KB

Design Patterns for Humans™ - An ultra-simplified explanation - C# Examples

C# 100.00%
csharp design-patterns factory-pattern prototype-pattern creational-patterns behavioral-patterns structural-patterns builder-pattern singleton-pattern adapter-pattern bridge-pattern composite-patterns decorator-pattern facade-pattern flyweight-pattern proxy-pattern chain-of-responsibility-pattern command-pattern iterator-pattern mediator-pattern

csharp-design-patterns-for-humans's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

csharp-design-patterns-for-humans's Issues

wrong output

Hi
last line of code in Prototype should print Jolly which is original.Name instead of Dolly

Singleton code example is not thread safe

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

Typo

Strategy using example:

var sorter = new Sorter(new QuickSortStrategy());
sorter.Sort(unSortedList); // // Output : Sorting using Bubble Sort !

QuickSortStrategy - > BubbleSortStrategy

Iterator pattern StackOverflowException

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;
            }
}

What ARE the problems or complexities alluded to in the text with regular object creation?

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.

Non conventional method name

At the Singleton example, get_instance() should be GetInstance().
Also there is a redundant call to .ToString().

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.