Overloading property vs. non-property
torhu
no at spam.invalid
Thu Jul 15 13:55:04 PDT 2010
On 15.07.2010 17:42, dsimcha wrote:
> == Quote from torhu (no at spam.invalid)'s article
>> In case the answer is no, that example of yours is the perfect
>> opportunity to dust off the almost-forgotten with statement :)
>> with (Histogram(someData, 10)) {
>> barColor = getColor(255, 0, 0);
>> histType = HistType.Probability;
>> toFigure.title = "A Histogram";
>> xLabel = "Stuff";
>> showAsMain();
>> }
>> A bit more typing, but I'd say that it's easier to read.
>
> But toFigure returns a Figure, not this. The idea is that you'd set all the
> properties for the Plot, then put toFigure somewhere in your chain, then set all
> the properties for the Figure.
Oops, guess I should have waited until after my nap with posting :)
You could nest the with statements, but then it's getting more verbose.
Might be better to add a convenience constructor or two to Figure that
takes care of the most common cases, and having toFigure forward to that.
with (Histogram(someData, 10)) {
barColor = getColor(255, 0, 0);
histType = HistType.Probability;
toFigure("A Histogram", "Stuff").showAsMain();
}
Other options include having a factory function that returns a
probability histogram, or even make it a template parameter and a have a
ProbabilityHistogram alias, etc. A few small changes could help a lot
for the common use cases. It would never be as quite flexible as what
you have now, but you might get close enough.
More information about the Digitalmars-d
mailing list