Solved

Explanation of How Second Constructor Is Working and Why Is Needed

Posted on 2012-04-05
2
330 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

MIM Survival Guide for Service Desk Managers

Major incidents can send mastered service desk processes into disorder. Systems and tools produce the data needed to resolve these incidents, but your challenge is getting that information to the right people fast. Check out the Survival Guide and begin bringing order to chaos.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The Confluence of Individual Knowledge and the Collective Intelligence At this writing (summer 2013) the term API (http://dictionary.reference.com/browse/API?s=t) has made its way into the popular lexicon of the English language.  A few years ago, …
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
This is a high-level webinar that covers the history of enterprise open source database use. It addresses both the advantages companies see in using open source database technologies, as well as the fears and reservations they might have. In this…
NetCrunch network monitor is a highly extensive platform for network monitoring and alert generation. In this video you'll see a live demo of NetCrunch with most notable features explained in a walk-through manner. You'll also get to know the philos…

729 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