Building Maintainable Software, C# Edition by Joost Visser

Building Maintainable Software, C# Edition by Joost Visser

Author:Joost Visser
Language: eng
Format: mobi, epub, pdf
Publisher: O'Reilly Media, Inc.
Published: 2016-06-21T16:00:00+00:00


public class BarChart { private CategoryItemRendererState state = CategoryItemRendererState.DEFAULT; private Rectangle graphArea = new Rectangle(new Point(0, 0), 100, 100); private CategoryPlot plot = CategoryPlot.DEFAULT; private CategoryAxis domainAxis = CategoryAxis.DEFAULT; private ValueAxis rangeAxis = ValueAxis.DEFAULT; private CategoryDataset dataset = CategoryDataset.DEFAULT; public BarChart Draw(Graphics g) { // .. return this; } public ValueAxis GetRangeAxis() { return rangeAxis; } public BarChart SetRangeAxis(ValueAxis rangeAxis) { this.rangeAxis = rangeAxis; return this; } // More getters and setters. }

The static method drawBarChart from the original version is replaced by the (nonstatic) method draw in this class. Six of the seven parameters of drawBarChart have been turned into of BarChart class. All of these have default values. We have chosen to keep parameter g (of type System.Drawing.Graphics) as a parameter of draw. This is a sensible choice: draw always needs a Graphics object, and there is no sensible default value. But it is not necessary: we could also have made g into the seventh private member and supplied a getter and setter for it.

We made another choice: all setters return this to create what is called a fluent interface. The setters can then be called in a cascading style, like so:



Download



Copyright Disclaimer:
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.