Solved

Explanation of How Second Constructor Is Working and Why Is Needed

Posted on 2012-04-05
2
316 Views
Last Modified: 2012-09-13
I am new to web development, and I was wondering if someone could explain to be what the purpose of the second constructor that is part of the partial BusMain class that is attached below. (I understand the purpose of the constructor. I was just wondering why you would need to have a second constructor with XML parameters in it.) Any help would be greatly appreciated.

 

//  Nancy Drew   January 12, 2023

//  Theoretical code to exemplify problem described in question

 

using System;

using System.Xml;

using System.Xml.Serialization;

using System.Collections;

using System.Collections.Generic;

 

namespace NS.Conn.LegalProject.Businesses.BUS_Entities

{

    [Serializable]

    public class BusMain:BusBase<BusMain>

    {

        #region Private Variables

 

        private bool legalDocumentationExists;

        private bool detailsExists;

        private bool nondetailsExists;

        private LegalDocumentation legalDocumentation;

        private List<detailsInformation> detailsInfos;

        private List<NondetailsInformation> nondetailsInfos;

      

 

        #endregion

 

        #region Constructors

 

        /// <summary>

        /// Default constructor.

        /// </summary>

        public BusMain()

        {

            this.nondetailsExists = false;

            this.detailsExists = false;

            this.legalDocumentationExists = false;

            this.legalDocumentation = new LegalDocumentation();

            this.detailsInfos = new List<detailsInformation>();

            this.nondetailsInfos = new List<NondetailsInformation>();

        }

 

        /// <summary>

        /// Constructor building the intstance from the Xml string.

        /// </summary>

        /// <param name="xmlString"></param>

        public BusMain(string xmlString)

            :this()

        {

            BusMain temp = this.FromXml(xmlString);

            this.NondetailsExists = temp.NondetailsExists;

            this.detailsExists = temp.detailsExists;

            this.LegalDocumentationExists = temp.LegalDocumentationExists;

            this.LegalDocumentation = temp.LegalDocumentation;

            this.detailsInfos = temp.detailsInfos;

            this.NondetailsInfos =temp.NondetailsInfos;

        }

 

        #endregion

 

        #region Public Properties

 

         public bool NondetailsExists

         {

             get{ return this.nondetailsExists;}

             set {this.nondetailsExists = value;}

         }

         public bool detailsExists

         {

             get{ return this.detailsExists;}

             set {this.detailsExists = value;}

         }

          public bool LegalDocumentationExists

         {

             get{ return this.legalDocumentationExists;}

             set {this.legalDocumentationExists = value;}

         }

        }

 

        public LegalDocumentation LegalDocumentation

        {

            get

            {

                return this.legalDocumentation;

            }

            set

            {

                this.legalDocumentation = value;

            }

        }

 

        public List<detailsInformation> detailsInfos

        {

            get

            {

                return this.detailsInfos;

            }

            set

            {

                if (value != null)

                {

                    this.detailsInfos = value;

                }

                else

                {

                    this.detailsInfos = new List<detailsInformation>();

                }

            }

 

        }

 

        public List<NondetailsInformation> NondetailsInfos

        {

            get

            {

                return this.nondetailsInfos;

            }

            set

            {

                if (value != null)

                {

                    this.nondetailsInfos = value;

                }

                else

                {

                    this.nondetailsInfos = new List<NondetailsInformation>();

                }

            }

        }

 

        #endregion

 

        #region Public Methods

 

        /// <summary>

        /// Checks if data in the instance is consistent with business rules.

        /// </summary>

        /// <returns></returns>

        public bool IsValid()

        {

            bool retValue = true;

 

            return retValue;

        }

 

        /// <summary>

        /// Checks if it has cover in NondetailsInformations collection.

        /// </summary>

        /// <returns></returns>

        public bool HasThisCover()

        {

            return this.HasCCover(CCovers.This);

        }

 

        /// <summary>

        /// Checks where it got c in NondetailsInformations collection.

        /// </summary>

        /// <returns></returns>

        public bool HasThatC()

        {

            return this.HasCObtainedThrough(CObtainedThrough.That);

        }

 

        #endregion

 

        #region Private Methods

 

        private bool HasCCover(CCovers cCover)

        {

            bool retValue = false;

            if (this.nondetailsInfos != null)

            {

                if (this.nondetailsInfos.Count > 0)

                {

                    foreach (NondetailsInformation nondetailsInformation in this.nondetailsInfos)

                    {

                        if ((nondetailsInformation.CCovers & cCover) == cCover)

                        {

                            retValue = true;

                            break;

                        }

                    }

                }

            }

            return retValue;

        }

 

        private bool HasCObtainedThrough(CObtainedThrough cObtainedThrough)

        {

            bool retValue = false;

            if (this.nondetailsInfos != null)

            {

                if (this.nondetailsInfos.Count > 0)

                {

                    foreach (NondetailsInformation nondetailsInfo in this.nondetailsInfos)

                    {

                        if (nondetailsInfo.CObtainedThrough == cObtainedThrough)

                        {

                            retValue = true;

                            break;

                        }

                    }

                }

            }

            return retValue;

        }

 

        #endregion

 

    }

}

Open in new window

0
Comment
Question by:thenthorn1010
  • 2
2 Comments
 
LVL 29

Expert Comment

by:Paul Jackson
ID: 37811948
The first constructor is creating an instance of the class with default values.
The second constructor is creating an instance of the class with the values taken from the xmlstring that is passed in.
0
 
LVL 29

Accepted Solution

by:
Paul Jackson earned 500 total points
ID: 37811974
The only purpose (I can think of) to the second constructor is to provide a way of initialising the class instance with values during instantation rather than having to set them after creation in the calling code.
0

Featured Post

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

Suggested Solutions

ASP.Net to Oracle Connectivity Recently I had to develop an ASP.NET application connecting to an Oracle database.As I am doing it first time ,I had to solve several problems. This article will help to such developers  to develop an ASP.NET client…
IntroductionWhile developing web applications, a single page might contain many regions and each region might contain many number of controls with the capability to perform  postback. Many times you might need to perform some action on an ASP.NET po…
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…

760 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now