GoF patterns in C#

  • Thread starter Thread starter myhotline
  • Start date Start date
M

myhotline

Hi there,

I was wondering from where i can get the source code of patterns
implemented in either C# or Vb.NET.
Any help or advice will be highly appreciated. Thanks in advance.
Regards,
-ANaive
 
Hi there,

I was wondering from where i can get the source code of patterns
implemented in either C# or Vb.NET.
Any help or advice will be highly appreciated. Thanks in advance.
Regards,
-ANaive

Hi:

I first apologize that I haven't tested all sources, but my patterns
expirience in .NET was for a little project beside University done in
VB.NET and this is a while ago. I also didn't read any groundwork, sinze
there was a patterns course at the University and I am a proud owner of
the GoF ;).

However:
Singelton, Abstract Factory and Observer is implemented in a Tech
article at the MSDN. These articles are quite good, although very basic
(but you don't need more, I think). There is also a series of MSDN
Webcastss about patterns, although I haven't watched them, so it would
be nice to provide some feedback if you watch them.


There is a website, http://www.dofactory.com/ which is too concerned
about patterns too, and it's code is implemented in .NET. You finde the
side under http://www.dofactory.com/Patterns/Patterns.aspx (or
http://www.dofactory.com/ -> Developer Ressourced -> Design Pattern Code
Library)

There is also a couple of books for patterns in VB and C# .NET, I too
haven't read them, but you might search amazon for Patterns .NET and
read the feedback!

:)
Jörg
 
"The Crow" <q> a écrit dans le message de (e-mail address removed)...

| http://www.dofactory.com/Patterns/Patterns.aspx

But bear in mind that some of the examples are by no means optimal due to
language features available in C#.

e.g. The Observer pattern using a multicast delegate :

public interface ISubject
{
event EventHandler Notify;
}

public interface IObserver
{
void Update(object sender, EventArgs e);
}

public class MySubject : ISubject
{
private EventHandler notify;

private void OnNotify(EventArgs e)
{
if (notify != null)
notify(this, e);
}

event EventHandler ISubject.Notify
{
add { notify += value; }
remove { notify -= value; }
}
}

public class MyObserver : IObserver
{
void IObserver.Update(object sender, EventArgs e)
{
Console.WriteLine(sender.ToString());
}
}

You don't have to use interfaces, but they provide the ability to derive
from other classes and to implement a pattern as well.

Test code can look something like this :

{
MySubject subject = new MySubject();

MyObserver observer = new MyObserver();

((ISubject) subject).Notify += ((IObserver) observer).Update;

subject.Trigger();

Console.ReadLine();
}

Joanna
 
Start with www.dofactory.com and also look in the book "Design Patterns in
C#" by Cooper. It has a CD in the back with code.

These are useful places for your study of DP.

--
--- Nick Malik [Microsoft]
MCSD, CFPS, Certified Scrummaster
http://blogs.msdn.com/nickmalik

Disclaimer: Opinions expressed in this forum are my own, and not
representative of my employer.
I do not answer questions on behalf of my employer. I'm just a
programmer helping programmers.
 
Back
Top