Note that there are some explanatory texts on larger screens.

plurals
  1. POCritique – OO Design Flaws
    text
    copied!<p>Recently, I received some negative feedback about the design of a class that I had originally thought to be innovative. After reflection, however, I agree it is clearly more flawed than innovative.</p> <p>This post invited the community to join in the review and provide its thoughtful feedback on the design flaws and identify a fix. </p> <p><strong>Background and Details:</strong></p> <p>The class in question is a domain object that gets dual-use in the business layer and in the UI. (Sometimes it is necessary.) </p> <p>The class includes a Display() Property that returns UI-friendly string. The rationale for including this Property is a convenience for class consumers. In my specific use, it was easy to bind a collection of this object to a UI grid control on the Display() Property.</p> <p>Display is implemented through a delegate so consumers can swap in another delegate.</p> <p><strong>Implementation</strong>:</p> <pre><code>//Within the "Measure" class is a delegate for the Display() public delegate string DisplayDelegate(IMeasure Measure); private DisplayDelegate _displayDelegate; </code></pre> <p>...</p> <pre><code>//The class uses a Write-Only Property sets the Display() delegate. //Within the constructor (not shown here), I set a default Display delegate by //concatenating a few properties together in a UI-friendly display string. public DisplayDelegate Display { set { _displayDelegate = value; } } //Class consumers call "MeasureDisplay" for a public string MeasureDisplay { get { return _displayDelegate.Invoke(this); } } </code></pre> <p>The responses below address the question of what is wrong with the design and what could fix it.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload