Difference between revisions of "Class Definitions"
(→Public Methods to Access DataItems) |
|||
Line 7: | Line 7: | ||
Class NameOfClass | Class NameOfClass | ||
+ | |||
+ | ==Sub Classes== | ||
+ | If your class is a subclass then you need to specify which class it is based upon: | ||
+ | |||
+ | NameOfClass = Class (ParentClass) | ||
+ | |||
+ | or | ||
+ | |||
+ | NameOfClass = Class of ParentClass | ||
+ | |||
+ | or | ||
+ | |||
+ | Class NameOfClass = ParentClass | ||
==Private data values== | ==Private data values== |
Revision as of 13:29, 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
Sub Classes
If your class is a subclass then you need to specify which class it is based upon:
NameOfClass = Class (ParentClass)
or
NameOfClass = Class of ParentClass
or
Class NameOfClass = ParentClass
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 }