¿Cuál de estos diseños es mejor? ¿Cuáles son los pros y los contras de cada uno? ¿Cuál usarías? Se agradece cualquier otra sugerencia sobre cómo tratar con métodos como.
Es razonable suponer que Draw () es el único lugar desde el que se llama a los otros métodos de dibujo. Esto necesita expandirse a muchos más métodos Draw * y Show *, no solo a los tres que se muestran aquí.
public void Draw()
{
if (ShowAxis)
{
DrawAxis();
}
if (ShowLegend)
{
DrawLegend();
}
if (ShowPoints && Points.Count > 0)
{
DrawPoints();
}
}
private void DrawAxis()
{
// Draw things.
}
private void DrawLegend()
{
// Draw things.
}
private void DrawPoints()
{
// Draw things.
}
O
public void Draw()
{
DrawAxis();
DrawLegend();
DrawPoints();
}
private void DrawAxis()
{
if (!ShowAxis)
{
return;
}
// Draw things.
}
private void DrawLegend()
{
if (!ShowLegend)
{
return;
}
// Draw things.
}
private void DrawPoints()
{
if (!ShowPoints || Points.Count <= 0))
{
return;
}
// Draw things.
}