Patterns in C#

Just finished the first 4 chapters for school, converted all the code to C# and well I have to admit that I used more patterns before then I realized.

One of the patterns that I don’t really like is the Singleton, well I have nothing against it, but if you start a new class with the singleton in mind you can use a static class instead, it’s easier to access Class.Method() instead of something like Class.Default.Method(), but if you have to convert an existing class it can be easier to make a singleton:

  • Make constructor private so no other class can call it
  • Keep a static field from the same type
  • Use a static public property to access the field (and create it if it’s still null)

But I just love the Strategy in combination with a Factory. Use the strategy to build the class hierachy and then use the Factory to get an instance to them.

This entry was posted in Uncategorized. Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>