Difference between revisions of "Class Definitions"

From TRCCompSci - AQA Computer Science
Jump to: navigation, search
(Created page with "==Declaration== A class should be declared, for any exam question you don't need to use a specific syntax or language: NameOfClass = Class or Class NameOfClass ==Private...")
 
(Public Methods to Access DataItems)
Line 20: Line 20:
 
  NameOfClass = Class
 
  NameOfClass = Class
 
     Private int DataItem1
 
     Private int DataItem1
    Private String DataItem2
 
 
     Public int GetDataItem1()
 
     Public int GetDataItem1()
 
     {  
 
     {  

Revision as of 14:26, 2 January 2017

Declaration

A class should be declared, for any exam question you don't need to use a specific syntax or language:

NameOfClass = Class

or

Class NameOfClass

Private data values

It is normal to make all of the data items within a class private. This means they can't be accessed outside of the class itself, this could prevent any rogue updates of the data values. For each data item, the name and datatype should be specified:

NameOfClass = Class
   Private int DataItem1
   Private String DataItem2

Public Methods to Access DataItems

In order to access the data items, public methods should be created. This way you have more control over your data items and can provide a very specific to access or change your data:

NameOfClass = Class
   Private int DataItem1
   Public int GetDataItem1()
   { 
      Return DataItem1
   }
   Public int SetDataItem1(int Value)
   {
      DataItem1 = Value
   }