Difference between revisions of "Composition - 2017"

From TRCCompSci - AQA Computer Science
Jump to: navigation, search
Line 26: Line 26:
  
 
</syntaxhighlight>
 
</syntaxhighlight>
 +
 +
As you can see Location is part of Simulation, so if you remove the class of Location, Simulation would not work as Location forms a variable within the class that is frequently used.

Revision as of 12:57, 7 February 2017

Composition is where if you delete the main class the subclasses are deleted along with it, or they no longer work.

  class Location
  {
    public Fox Fox;
    public Warren Warren;

    public Location()
    {
      Fox = null;
      Warren = null;
    }
  }

  class Simulation
  {
    private Location[,] Landscape;
    private int TimePeriod = 0;
    private int WarrenCount = 0;
    private int FoxCount = 0;
    private bool ShowDetail = false;
    private int LandscapeSize;
    private int Variability;
    private static Random Rnd = new Random();

As you can see Location is part of Simulation, so if you remove the class of Location, Simulation would not work as Location forms a variable within the class that is frequently used.