Reply To: Is there something between a public variable and a static public variable?

Forum Archive Is there something between a public variable and a static public variable? Reply To: Is there something between a public variable and a static public variable?

#38204
Will
Participant

    Here’s how that might look:

    public class Family 

    {

        // Add any shared properties here

        public string Name {get;set;}

    }

    public class Animal

    {

        // this could be public, or keep it more internal

        protected Family Family { get;set; }

        public Animal(Family fam)

        {

            Family = fam;

        }

        // you’ll probably want to do somethng more useful than this, but it should

        // give you the idea

        public string FamilyName

        {

            get { return Family.Name; }

        }

    }

    public class SpecificAnimal : Animal

    {

        public SpecificAnimal(Family fam)

            : base(fam) // pass the family instance into the base class

        {

            // do any other setup here

        }

        public void DoSomething()

        {

            // we can access the Family properties from in this specific class too

            var name  = Family.Name;

        }

    }