Accessor Method

Our invader class still empty, we will code it up now. One attribute the invader should have is its location on the map. We need this in order to determine how close they are to towers, to see if they're in range of each other.

We will use method to get and set the location of invader. This get and set method known as accessor method.

class Invader
{
    private MapLocation _location;

    public MapLocation GetLocation()
    {
        return _location;
    }

    public void SetLocation(MapLocation value)
    {
        _location = value;
    }
}

The main idea is to make all fields being private and write public getters and setters to access it indirectly.

results matching ""

    No results matching ""