Difference between revisions of "Composition - 2017"

From TRCCompSci - AQA Computer Science
Jump to: navigation, search
Line 28: Line 28:
  
 
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.
 
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.
 +
 +
==Other Examples==
 +
 +
Warrens & Rabbits - warren creates and destroys rabbits
 +
Foxes & Warrens - both are ultimately created and destroyed by the simulation

Revision as of 15:00, 21 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.

Other Examples

Warrens & Rabbits - warren creates and destroys rabbits Foxes & Warrens - both are ultimately created and destroyed by the simulation