Difference between revisions of "2022 - Challenge"

From TRCCompSci - AQA Computer Science
Jump to: navigation, search
(Created page with "=The Code= <syntaxhighlight lang=c#> class Challenge { protected List<string> Condition; protected bool Met; public Challenge() {...")
 
(Methods)
 
Line 43: Line 43:
 
=Methods=
 
=Methods=
 
Interestingly, none of the methods within this class are declared as virtual. This means they can't be overridden in any subclass.
 
Interestingly, none of the methods within this class are declared as virtual. This means they can't be overridden in any subclass.
 +
 +
The all seem to be accessor methods for the protected variables and structures.

Latest revision as of 12:49, 23 December 2021

The Code

class Challenge
    {
        protected List<string> Condition;
        protected bool Met;

        public Challenge()
        {
            Met = false;
        }

        public bool GetMet()
        {
            return Met;
        }

        public List<string> GetCondition()
        {
            return Condition;
        }

        public void SetMet(bool newValue)
        {
            Met = newValue;
        }

        public void SetCondition(List<string> newCondition)
        {
            Condition = newCondition;
        }
    }

Variables

The class defines a List of strings called Condition. This is protected, which means it is available in any subclass created from Challenge.

The class also defines a boolean called 'Met'. This is also protected.

The Constructor

The constructor method only sets the Met boolean to false.

Methods

Interestingly, none of the methods within this class are declared as virtual. This means they can't be overridden in any subclass.

The all seem to be accessor methods for the protected variables and structures.