Difference between revisions of "Class Definitions"
Line 41: | Line 41: | ||
DataItem1 = Value | DataItem1 = Value | ||
} | } | ||
+ | |||
+ | ==Static, Abstract, Virtual== | ||
+ | <h2>Static</h2> | ||
+ | The "static" modifier means that a class cannot be instantiated, and the subroutines must instead be called directly. | ||
+ | |||
+ | if you had a class of human and created an instance of the human called wayne, the static modifier doesn't allow access such as wayne.example() , or wayne.example = 5, or Console.WriteLine(wayne.example). They are not avialable in an instance of a class. | ||
+ | |||
+ | <h2>Abstraction</h2> | ||
+ | The "abstract" modifier when declaring a class means that the class contains one or more abstract subroutine, and must have one or more subclasses for implementations of abstract methods. A subclass of an abstract class that is instantiated must implement any abstract subroutines contained in the abstract class. | ||
+ | |||
+ | <h2>Virtual</h2> | ||
+ | A virtual method is one which is inheritable and can be overridden. |
Revision as of 13:32, 2 January 2017
Contents
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 }
Static, Abstract, Virtual
Static
The "static" modifier means that a class cannot be instantiated, and the subroutines must instead be called directly.
if you had a class of human and created an instance of the human called wayne, the static modifier doesn't allow access such as wayne.example() , or wayne.example = 5, or Console.WriteLine(wayne.example). They are not avialable in an instance of a class.
Abstraction
The "abstract" modifier when declaring a class means that the class contains one or more abstract subroutine, and must have one or more subclasses for implementations of abstract methods. A subclass of an abstract class that is instantiated must implement any abstract subroutines contained in the abstract class.
Virtual
A virtual method is one which is inheritable and can be overridden.