|
using System.Windows.Forms;
namespace OCP
{
/// <summary>
/// This class violates OC principle.Furthermore
/// to add, this class is classic example of
/// Singleton pattern.
/// </summary>
class ImageOperations
{
/// <summary>
///
/// </summary>
private static ImageOperations m_ImageOperations = null;
/// <summary>
///
/// </summary>
private ImageOperations() { }
/// <summary>
/// Single instance
/// </summary>
public static ImageOperations Singleton
{
get
{
if (m_ImageOperations == null)
{
m_ImageOperations = new ImageOperations();
}
return m_ImageOperations;
}
}
/// <summary>
/// DrawImages function violates OCP principle.
/// Later if some other shapes are added say Polygon
/// or Trigonal. This function code will be changed.
/// In order to follow OCP principle in such kind
/// of scenario please make use of Factory Pattern.
/// </summary>
/// <param name="shapeType"></param>
/// <param name="frm"></param>
public void DrawImages(string shapeType, Form frm)
{
IShapes shapes = null;
switch (shapeType)
{
case "SQUARE":
shapes = new Square();
break;
case "RECTANGLE":
shapes = new Rectangle();
break;
case "ELLIPSE":
shapes = new Ellipse();
break;
}
if (shapes != null) shapes.DrawShapes(frm);
}
}
}
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.