none
Design Pattern RRS feed

  • Question

  • Please provide the links for simple sample code for design pattern implementation in c#.
    Friday, August 14, 2009 6:47 AM

Answers

  • Hi - Here are some good and helpful link.

    MSDN Magazine: Design Pattern.
    http://msdn.microsoft.com/en-us/magazine/cc301852.aspx

    C# Design Patter Made Simple:
    http://en.csharp-online.net/CSharp_Design_Patterns_Made_Simple

    If you are searching for good working C# samples:
    Check out: http://cfx.codeplex.com

    I hope this information was helpful...

    Have a nice day...

    Best regards,
    Fisnik
    Coder24.com
    • Proposed as answer by Rahul P Nath Friday, August 14, 2009 1:13 PM
    • Marked as answer by Harry Zhu Friday, August 21, 2009 6:02 AM
    Friday, August 14, 2009 9:25 AM
  • Technically, the implementation of a design pattern is a design, so there is no code at that point.

    However, an implementation of an example implementation of a design pattern could have example code. :)

    If you want to learn more about design patterns, I recommend the classic GoF. That's "Gang of Four", as they were called in the fall of '99 when I first heard of "design patterns". This is one of the very few books that has actually changed the way I think about software.

            -Steve
    Programming blog: http://nitoprograms.blogspot.com/
      Including my TCP/IP .NET Sockets FAQ
    MSBuild user? Try out the DynamicExecute task in the MSBuild Extension Pack source; it's currently in Beta so get your comments in!
    I will be at the Grand Rapids BarCamp 4 unconference - come on by, fellow Michiganders!
    • Proposed as answer by Rudedog2Moderator Friday, August 14, 2009 5:48 PM
    • Marked as answer by Harry Zhu Friday, August 21, 2009 6:03 AM
    Friday, August 14, 2009 1:06 PM
  • The 23 Gang of Four Design Patterns (Cheat Sheet)

     

    1. Strategy:

    Defines a family of algorithms, encapsulates each one, and make them interchangeable. Strategy lets the algorithm vary independently from clients who use it.

     

    2. Decorator:

    Attach additional responsibilities to an object dynamically. Decorators provide a flexible alternative to subclassing for extending functionality.

     

    3. Factory Method

    Define an interface for creating an object, but let the subclasses decide which class to instantiate. Factory Method lets a class defer instantiation to subclasses.

     

    4. Observer

    Define a one-to-many dependency between objects so that when one object changes state, all its dependents are notified and updated automatically.

     

    5. Chain of Responsibility

    Avoid coupling the sender of a request to its receiver by giving more then one object a chance to handle the request. Chain the receiving objects and pass the request along the chain until an object handles it.

     

    6. Singleton

    Ensure a class only has one instance, and provide a global point of access to it.

     

    7. Flyweight

    Use sharing to support large numbers of fine-grained objects efficiently. A flyweight is a shared object that can be used in multiple contexts simultaneously. The flyweight acts as an independent object in each context; it’s indistinguishable from an instance of the object that’s not shared.

     

    8. Adapter

    Convert the interface of a class into another interface clients expect. Adapter lets classes work together that couldn’t otherwise because of incompatibility interfaces.

     

    9. Façade

    Provide a unified interface to a set of interfaces in a system. Façade defines a higher-level interface that makes the subsystem easier to use.

     

    10. Template

    Define a skeleton of an algorithm in an operation, deferring some steps to subclasses. Template Method lets subclasses redefine certain steps of an algorithm without changing the algorithms structure.

     

    11. Builder

    Separate the construction of a complex object from its representation so that the same construction processes can create different representations.

     

    12. Iterator

    Provide a way to access the elements of an aggregate object sequentially without exposing its underlying representation.

     

    13. Composite

    Compose objects into tree structures to represent part-whole hierarchies. Composite lets clients treat individual objects and compositions of objects uniformly.

    14. Command

    Encapsulate a request as an object, thereby letting you parameterize clients with different requests, queue or log requests, and support undoable operations.

     

    15. Mediator

    Define an object that encapsulates how a set of objects interact. Mediator promotes loose coupling by keeping objects from referring to each other explicitly, and lets you vary their interaction independently.

     

    16.  State

    Allow an object to alter its behavior when its internal state changes. The object will appear to change its class.

     

    17. Proxy

    Provide a surrogate or placeholder for another object to control access to it.

     

    18. Abstract Factory

    Provide an interface for creating families of related or dependent objects without specifying their concrete classes.

     

    19. Bridge

    Decouple an abstraction from its implementation so that the two can vary independently.

     

    20. Interpreter

    Given a language, define a representation for its grammar along with an interpreter that uses the representation to interpret sentences in the language.

     

    21. Memento

    Without violating encapsulation, capture and externalize an object’s internal state so that the object can be restored to this state later.

     

    22. Prototype

    Specify the kinds of objects to create using a prototypical instance, and create new objects by copying this prototype.

     

    23. Visitor

    Represent an operation to be performed on the elements of an object structure. Visitor lets you define a new operation without changing the classes of the elements on which it operates.


    John Grove - TFD Group, Senior Software Engineer, EI Division, http://www.tfdg.com
    • Marked as answer by Harry Zhu Friday, August 21, 2009 6:03 AM
    Friday, August 14, 2009 2:11 PM
  • Hello,

    Continuing 'Stephen Cleary' above, it's important to understand that design patterns are merely a concept to solution of a problem, not an actual implementation.

    I think that the GoF book suggested above is an awesome one, also, here are few books that I think are important just as much.

    * The Object-Oriented Thought Process (beginners)
    * Design Patterns Explained (beginners - advanced)
    * Design Patterns Elements of Reusable Object Oriented Software (reference/advanced)

    Here are more links.

    Design Patterns (book)
    http://en.wikipedia.org/wiki/Design_Patterns_(book)

    Application design and architecture related articles Submit your article
    http://www.codeproject.com/KB/architecture/

    Implementing the Singleton Pattern in C#
    http://www.yoda.arachsys.com/csharp/singleton.html


    Eyal, Regards.
    • Marked as answer by Harry Zhu Friday, August 21, 2009 6:03 AM
    Friday, August 14, 2009 5:17 PM
  • Hi,
    I hope it will help you.

    from msdn
    http://msdn.microsoft.com/en-us/magazine/cc301852.aspx

    from bing search you can get lot of articles

    http://www.bing.com/search?q=design+pattern+c%23+msdn&form=QBLH&filt=all&qs=n


    Best Regards, C.Gnanadurai ----------------------- Please mark the post as answer if it is helpfull to you
    • Marked as answer by Harry Zhu Friday, August 21, 2009 6:03 AM
    Friday, August 14, 2009 9:26 AM
  • GoF - Gang of Four Original 23 Design Patterns



    Mark the best replies as answers. "Fooling computers since 1971."
    • Marked as answer by Harry Zhu Friday, August 21, 2009 6:03 AM
    Friday, August 14, 2009 1:25 PM
    Moderator

All replies

  • Hi Kumar,

    What design pattern do you want to implement using C#? Could you be more clear on the question.

    Regards,
    Vishal Mohan

    Friday, August 14, 2009 9:22 AM
  • Hi - Here are some good and helpful link.

    MSDN Magazine: Design Pattern.
    http://msdn.microsoft.com/en-us/magazine/cc301852.aspx

    C# Design Patter Made Simple:
    http://en.csharp-online.net/CSharp_Design_Patterns_Made_Simple

    If you are searching for good working C# samples:
    Check out: http://cfx.codeplex.com

    I hope this information was helpful...

    Have a nice day...

    Best regards,
    Fisnik
    Coder24.com
    • Proposed as answer by Rahul P Nath Friday, August 14, 2009 1:13 PM
    • Marked as answer by Harry Zhu Friday, August 21, 2009 6:02 AM
    Friday, August 14, 2009 9:25 AM
  • Hi,
    I hope it will help you.

    from msdn
    http://msdn.microsoft.com/en-us/magazine/cc301852.aspx

    from bing search you can get lot of articles

    http://www.bing.com/search?q=design+pattern+c%23+msdn&form=QBLH&filt=all&qs=n


    Best Regards, C.Gnanadurai ----------------------- Please mark the post as answer if it is helpfull to you
    • Marked as answer by Harry Zhu Friday, August 21, 2009 6:03 AM
    Friday, August 14, 2009 9:26 AM
  • Hi Kumar,

    What design pattern do you want to implement using C#? Could you be more clear on the question.

    Regards,
    Vishal Mohan


    yes ,the quesition must be more clear
    what design pattern do u want to implement using c#?
    Friday, August 14, 2009 9:43 AM
  • Technically, the implementation of a design pattern is a design, so there is no code at that point.

    However, an implementation of an example implementation of a design pattern could have example code. :)

    If you want to learn more about design patterns, I recommend the classic GoF. That's "Gang of Four", as they were called in the fall of '99 when I first heard of "design patterns". This is one of the very few books that has actually changed the way I think about software.

            -Steve
    Programming blog: http://nitoprograms.blogspot.com/
      Including my TCP/IP .NET Sockets FAQ
    MSBuild user? Try out the DynamicExecute task in the MSBuild Extension Pack source; it's currently in Beta so get your comments in!
    I will be at the Grand Rapids BarCamp 4 unconference - come on by, fellow Michiganders!
    • Proposed as answer by Rudedog2Moderator Friday, August 14, 2009 5:48 PM
    • Marked as answer by Harry Zhu Friday, August 21, 2009 6:03 AM
    Friday, August 14, 2009 1:06 PM
  • GoF - Gang of Four Original 23 Design Patterns



    Mark the best replies as answers. "Fooling computers since 1971."
    • Marked as answer by Harry Zhu Friday, August 21, 2009 6:03 AM
    Friday, August 14, 2009 1:25 PM
    Moderator
  • The 23 Gang of Four Design Patterns (Cheat Sheet)

     

    1. Strategy:

    Defines a family of algorithms, encapsulates each one, and make them interchangeable. Strategy lets the algorithm vary independently from clients who use it.

     

    2. Decorator:

    Attach additional responsibilities to an object dynamically. Decorators provide a flexible alternative to subclassing for extending functionality.

     

    3. Factory Method

    Define an interface for creating an object, but let the subclasses decide which class to instantiate. Factory Method lets a class defer instantiation to subclasses.

     

    4. Observer

    Define a one-to-many dependency between objects so that when one object changes state, all its dependents are notified and updated automatically.

     

    5. Chain of Responsibility

    Avoid coupling the sender of a request to its receiver by giving more then one object a chance to handle the request. Chain the receiving objects and pass the request along the chain until an object handles it.

     

    6. Singleton

    Ensure a class only has one instance, and provide a global point of access to it.

     

    7. Flyweight

    Use sharing to support large numbers of fine-grained objects efficiently. A flyweight is a shared object that can be used in multiple contexts simultaneously. The flyweight acts as an independent object in each context; it’s indistinguishable from an instance of the object that’s not shared.

     

    8. Adapter

    Convert the interface of a class into another interface clients expect. Adapter lets classes work together that couldn’t otherwise because of incompatibility interfaces.

     

    9. Façade

    Provide a unified interface to a set of interfaces in a system. Façade defines a higher-level interface that makes the subsystem easier to use.

     

    10. Template

    Define a skeleton of an algorithm in an operation, deferring some steps to subclasses. Template Method lets subclasses redefine certain steps of an algorithm without changing the algorithms structure.

     

    11. Builder

    Separate the construction of a complex object from its representation so that the same construction processes can create different representations.

     

    12. Iterator

    Provide a way to access the elements of an aggregate object sequentially without exposing its underlying representation.

     

    13. Composite

    Compose objects into tree structures to represent part-whole hierarchies. Composite lets clients treat individual objects and compositions of objects uniformly.

    14. Command

    Encapsulate a request as an object, thereby letting you parameterize clients with different requests, queue or log requests, and support undoable operations.

     

    15. Mediator

    Define an object that encapsulates how a set of objects interact. Mediator promotes loose coupling by keeping objects from referring to each other explicitly, and lets you vary their interaction independently.

     

    16.  State

    Allow an object to alter its behavior when its internal state changes. The object will appear to change its class.

     

    17. Proxy

    Provide a surrogate or placeholder for another object to control access to it.

     

    18. Abstract Factory

    Provide an interface for creating families of related or dependent objects without specifying their concrete classes.

     

    19. Bridge

    Decouple an abstraction from its implementation so that the two can vary independently.

     

    20. Interpreter

    Given a language, define a representation for its grammar along with an interpreter that uses the representation to interpret sentences in the language.

     

    21. Memento

    Without violating encapsulation, capture and externalize an object’s internal state so that the object can be restored to this state later.

     

    22. Prototype

    Specify the kinds of objects to create using a prototypical instance, and create new objects by copying this prototype.

     

    23. Visitor

    Represent an operation to be performed on the elements of an object structure. Visitor lets you define a new operation without changing the classes of the elements on which it operates.


    John Grove - TFD Group, Senior Software Engineer, EI Division, http://www.tfdg.com
    • Marked as answer by Harry Zhu Friday, August 21, 2009 6:03 AM
    Friday, August 14, 2009 2:11 PM
  • I read that book at least once a year.
    Friday, August 14, 2009 2:43 PM
  • Michael, did you ever see this:

    Interesting Abstract Factory Pattern by Judith Bishop
    John Grove - TFD Group, Senior Software Engineer, EI Division, http://www.tfdg.com
    Friday, August 14, 2009 2:47 PM
  • I read that book at least once a year.


    Ha. Ha.  Once o month.

    Mark the best replies as answers. "Fooling computers since 1971."
    Friday, August 14, 2009 2:56 PM
    Moderator
  • Good link John, thanks. I copied over to VS so I can see it formatted and work through the code. I am getting so dependent on the VS IDE ( and older ) I have to work harder to read plain text over 10 lines long :).

    Ha, with all the other stuff I have to read just to keep up I can only get to it once a year.  It was easier when K&R and a UNIX manual was the only thing you had to read.

    Friday, August 14, 2009 3:06 PM
  • I hear ya. We programmers have to learn so much:

    1.) C#, VB.NET, other languages
    2.) Relational DBMS, SQL Server, Access, others
    3.) ADO.NET
    4.) LINQ
    5.) UI, Security, Reflection, P/Invoke, Install
    6.) Xml, HTML, CSS, SGML

    The list gets bigger and bigger........and almost on a daily basis.
    John Grove - TFD Group, Senior Software Engineer, EI Division, http://www.tfdg.com
    Friday, August 14, 2009 4:02 PM
  • Hello,

    Continuing 'Stephen Cleary' above, it's important to understand that design patterns are merely a concept to solution of a problem, not an actual implementation.

    I think that the GoF book suggested above is an awesome one, also, here are few books that I think are important just as much.

    * The Object-Oriented Thought Process (beginners)
    * Design Patterns Explained (beginners - advanced)
    * Design Patterns Elements of Reusable Object Oriented Software (reference/advanced)

    Here are more links.

    Design Patterns (book)
    http://en.wikipedia.org/wiki/Design_Patterns_(book)

    Application design and architecture related articles Submit your article
    http://www.codeproject.com/KB/architecture/

    Implementing the Singleton Pattern in C#
    http://www.yoda.arachsys.com/csharp/singleton.html


    Eyal, Regards.
    • Marked as answer by Harry Zhu Friday, August 21, 2009 6:03 AM
    Friday, August 14, 2009 5:17 PM