Tag Archives: Framework

Anti-Patterns with CONSTANTS.

I have a habit that’s probably an anti-pattern. I like to nest classes in a constants file.

  1. I always call the file Constant.cs. Singular. It goes at the root level of my Framework project. This should be accessable from every other project within your solution.
  2. The class is a static. Therefore, all of the subclasses are static as well.

Normal Constant file

public static class Constant
{
  public const string Title = "My Title";
  public const string EmailAddress = "foo@bar.com";
 }

Now consider this…

Nested classes

public static class Constant
    {
 
        public const string Title = "My Title";
        public const string EmailAddress = "foo@bar.com";
 
        public static class Color
        {
            
            public static class White
            {
                public const string Name = "White";
                public const string HexCode = "#FFFFFF";
            }
 
            public static class Black
            {
                public const string Name = "Black";
                public const string HexCode = "#000000";
            }
 
        }
 
    }

Usage

public class Usage
    {
        public void Example()
        {
            var blackHexCode = Constant.Color.Black.HexCode;
        }
    }

I like how this creates a clean hierarchy to reference a constant. As I said, this is probably an anti-pattern. But it works for me.

Business object base class

I have three different projects converging.  They all need a more feature rich base class in the business layer.

I haven’t settled on a name for this base class.  EntityBase? BusinessBase?  BusinessObject?  I expect something will stick in the near future.

Proposed interfaces:

You should notice that most of these interfaces are pre-existing Microsoft interfaces.  ISupportUndo and ITrackStatus are inspired by Rockford Lhotka’s  CSLA framework.  The details are changed, but I really like the syntax to make the interface more readable.  “I support undo.”  I can’t think of a better way to express what the interface does.  Can you?

I’m still working on the implementation details.  I’ll share more once I have a stable sample app.