Monday, August 29, 2011

strange to have setters without getters

I have refactored my doings from yesterday and the day before as is shown here. Joel thought it was too strange to have setters without getters. He felt the code would be difficult for others to follow.

using System;

namespace MyApp.Helpers

{

   public class SearchParametersForFoo : AttributeNormalizationLayer

   {

      public string Name

      {

         get

         {

            if (Get("Name") == null) return null;

            return Get("Name").ToString();

         }

         set

         {

            Set("Name", value);

         }

      }

      

      public Int32? Number

      {

         get

         {

            if (Get("Number") == null) return null;

            return Convert.ToInt32(Get("Number"));

         }

         set

         {

            Set("Number", value);

         }

      }

   }

}

 
 

The base class:

using System.Collections;

namespace MyApp.Helpers

{

   public class AttributeNormalizationLayer

   {

      public Hashtable Collection = new Hashtable();

      

      public void Set(string name, object value)

      {

         if (value != null)

         {

            Collection.Add(name, value.ToString());

         }

      }

      

      public object Get(string name)

      {

         var returnValue = (object)Collection[name];

         return returnValue;

      }

   }

}

No comments:

Post a Comment