Good source code that could gives me head start on factory design pattern on c

De openkb
Aller à : Navigation, rechercher

Sommaire

Questions

I feel that I should start using the factory method design pattern on some of my code. Here is what I am doing;

The below code is my generator class for Accom namespace:

namespace Accom {

    public class Generator {

      int? _id;
      string _name;

      public Generator(int? id = null, string name = null) {
          _id = id;
          _name = name;
      }

      public string GetBaseUrl() { 

          //some logic sits here.

          return somestring;

      }

      //Can have some other methods as well

    }

}

I will have the same start-up for Traf namespace as well:

namespace Traf {
    public class Generator {
      int? _id;
      string _name;

      public Generator(int? id = null, string name = null) {
          _id = id;
          _name = name;
      }

      public string GetBaseUrl() { 
          //some logic sits here. Same one with the Accom.

          return somestring;
      }

      //Can have some other methods as well
    }
}

So, this will repeat again and again.

I tried to create some factory pattern for that but all of the abstract classes were mixed and I confused a lot (I think it is because this is first time I am trying to do something like that).

Can anyone help me on this and point me to good source code that I can read and get a sense from?

Answers

There are several sites I have bookmarked to help me learn the common design patterns.

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

http://en.csharp-online.net/CSharp_Design_Patterns_Made_Simple http://en.csharp-online.net/CSharp_Design_Patterns_Made_Simple

http://dpatoolkit.sourceforge.net/ http://dpatoolkit.sourceforge.net/

http://www.blackwasp.co.uk/DesignPatternsArticles.aspx http://www.blackwasp.co.uk/DesignPatternsArticles.aspx

Source

License : cc by-sa 3.0

http://stackoverflow.com/questions/6845105/good-source-code-that-could-gives-me-head-start-on-factory-design-pattern-on-c-s

Related

Outils personnels
Espaces de noms

Variantes
Actions
Navigation
Outils