Skip to content

Instantly share code, notes, and snippets.

@AnthonyMastrean
Last active August 29, 2015 14:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save AnthonyMastrean/472cb48e667be72cee53 to your computer and use it in GitHub Desktop.
Save AnthonyMastrean/472cb48e667be72cee53 to your computer and use it in GitHub Desktop.
Bloated Constructor
public class ActiveProduct
{
private readonly ActiveProductState State = ActiveProductState.Simulated;
private readonly SortedList<string, Environment> Environments = new SortedList<string, Environment>();
private readonly ProgramSlots AvailablePrograms = new ProgramSlots(this) { HIStartIndex = 0 };
private readonly ProgramSlots AccessoryPrograms = new ProgramSlots(this) { CanRemoveOverride = true, StartIndex = 4, IsAutoShifting = false };
private readonly ProgramSlots VirtualPrograms = new ProgramSlots(this) { IsVirtual = true, CanRemoveOverride = true, SlotConfig = Limit.None };
private readonly ProgramCalculator SlotCalculator = new ProgramCalculator(this, false);
private readonly ProgramCalculator VirtualCalculator = new ProgramCalculator(this, true);
private readonly DFSCalibration DFS = new DFSCalibration(this);
private readonly Accessories Accessories = new Accessories();
private readonly PowerBands PowerBands = PowerBands.Unknown;
private readonly Product Product;
private readonly StringVersion CurrentDriver;
private readonly Side Side;
private readonly Device Device;
private readonly Options Options { get { _Product.AvailableOptions; } };
public ActiveProduct(Product product, StringVersion driver, Side es, Device device)
{
if (product == null)
throw new Exception("Can't create an active product from a null product");
Product = product;
CurrentDriver = driver;
Side = es;
Device = device;
}
public void StartMonitoring()
{
Device.ConnectionStatus += Device_ConnectionStatus;
Device.BatteryStatus += Device_BatteryStatus;
}
}
@AnthonyMastrean
Copy link
Author

A look at the bloated constructor and some options... http://www.daedtech.com/beware-the-bloated-constructor

  • Field initialization should occur in the field declaration when possible (is this is in scope there?)
  • The try... catch is unnecessary except for the logging in the finally block
  • Logging should occur outside, when necessary, in the caller or object builder
  • Driver decision making should occur outside in the object builder
  • Device construction should occur outside in the object builder

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment