Code Standards

Microsoft Guidelines & Best Practices

using System;
using System.Collections.Generic;
using System.Text;
 
namespace TalkParty
{
    enum Emotions { Ecstatic, Happy, Indifferent, Sad, Depressed };
 
    public abstract class Talker
    {
        #region Private Constants
 
        private const int adultAge = 18;
 
        #endregion
 
        #region Protected Properties
 
        protected string _name;
        protected int _age;
        protected Emotions _emotion;
 
        #endregion
 
        #region Get/Set
 
        public string Name
        {
            get { return _name; }
            set { _name = value; }
        }
 
        public int Age
        {
            get { return _age; }
            set { _age = value; }
        }
 
        public Emotions Emotion
        {
            get { return _emotion; }
        }
 
        #endregion
 
        #region Constructors
 
        public Talker()
        {
        }
 
        public Talker(string name, int age, Emotions emotion)
        {
            _name = name;
            _age = age;
            _emotion = emotion;
        }
 
        #endregion
 
        // Virtual methods have implementations and may be overriden by the
        // derived class through the use of the override keyword.
        #region Virtual Methods
 
        /// <summary>
        /// Standard greeting provided from a Talker.
        /// </summary>
        public virtual void Greeting()
        {
            Console.WriteLine("Hello, world!  My name is {0}.", _name);
        }
 
        /// <summary>
        /// Standard farewell provided from a Talker.
        /// </summary>
        public virtual void Farewell()
        {
            Console.WriteLine("Goodbye.");
        }
 
        #endregion
 
        // Abstract methods have no implementation and are required to be
        // overriden by the derived class.
        #region Abstract Methods
 
        /// <summary>
        /// Hearing a story affects a Talker's emotional level.
        /// </summary>
        /// <param name="emotion">Emotional tone of the story.</param>
        public abstract void hearStory(Emotions emotion);
 
        #endregion
 
        // Regular methods haave implementations and cannot be overriden by a
        // derived class.
        #region Public Methods
 
        /// <summary>
        /// Determine if a Talker is over or equal to the age of adultAge.
        /// </summary>
        /// <returns>Status of adulthood.</returns>
        public Boolean IsAdult()
        {
            return _age >= adultAge;
        }
 
        /// <summary>
        /// Determine if a Talker is content enough to continue talking.
        /// </summary>
        /// <returns>Whether or not a Talker is in the mood to talk.</returns>
        public Boolean ContinueTalking()
        {
            if (_emotion == Emotions.Depressed)
                return false;
            else
                return true;
        }
 
        #endregion
    }
}
Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-Share Alike 2.5 License.