- On/Off switch
- Volume Control - a number 1-10.
- Channel Selector
Now in programming this, there are two ways to model a TV - the procedural approach in languages like C or Basic or the more modern OOP approach in C++, C# or Java.
In the procedural approach we use variables to hold the TVs 'values'. A boolean on/off value, an integer number for the volume control and another for the channel. These values are accessible anywhere in our source code where it accesses the TVs variables. Its easy to introduce subtle bugs such as too large a number in the volume control or writing to the wrong variable.
Think of the procedural approach as being as if our TV had no casing and that you had to use a screwdriver to change the volume or channel settings. It would be very dangerous! One slip and you might short something out. Accidentally changing a TV variable somewhere in your program could stop your program!
With OOP, the controls are wrapped up inside a TV object and the only way to change them is by calling 'accessor' functions. Our TV now has a 'case' and you can only change the settings by toggling the on/off switch or changing the volume and channel controls. That's much safer to operate. This is known as encapsulation - putting everything inside a 'case' and limiting access.
Our TV object has the following members. This is what it would look like in C++ syntax.
// private data, not publicly accessiblebool OnOff;
int volume;
int channel;
// accessor methods
SwitchOn() ;
SwitchOff() ;
SetVolume( int volume ) ;
SetChannel( int channel) ;
int GetVolume() ;
int GetChannel() ;

