Click here to Skip to main content
15,886,199 members
Articles / Programming Languages / XML

Is Code Complete?

Rate me:
Please Sign up or sign in to vote.
4.86/5 (77 votes)
11 Nov 2018CPOL9 min read 106.2K   357   221  
Design principles to be followed in software development
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.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
India India
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions