Thursday, March 26, 2015

Break the Law Of Demeter and reach into a nested enum in C#!

public void Report(List<Tuple<decimal,Measurement.TemperatureGauge>>)
{
   
//whatever

 
 

...should let you just have at...

public class Measurement
{
   public enum TemperatureGauge
   {
      Celsius,
      Fahrenheit,
      Kelvin
   }

 
 

...but I don't really recommend it. It you're gonna use nested classes and enums they should probably be private so that only the class wrapping them may mess with them. This is kinda like JavaScript encapsulation where one puts a function inside of a function so that only the wrapping function may use the encapsulated thing. Until now I've always thought nested classes/enums were pretty ghetto, but I suppose they can have their place. They suddenly seem more legit as I've typed what I've typed above. You'd want to make them private.

No comments:

Post a Comment