Main Content

Teaching OO - how to avoid lots of window switching early on

Archive - Originally posted on "The Horse's Mouth" - 2013-01-17 17:21:18 - Graham Ellis

One of the major benefits of Object Oriented programming is the clear and sharp dividing lines it provides between the different sections of logic - where code dealing with one type of data is specified, written, stored and tested in different files to the code dealing with other types of data (or code that bolts the whole lot together). Such separation allows easy code reuse, easy code update without the risk of side effects leaking right through the application, and easy testing and provision of demonstration pieces to show how elements are used.

Alas - it's not all a bed of roses. When teaching OO styles, the separation of code into different files can give rise to a whole lot of edit windows and a lot of hopping and skipping around to the confusion of delegates learning the principles for the first time ... and over time we've developed techniques to help with that. In C++, which I was teaching yesterday, I'll write the various elements:
• the API (Application / Programmer Interface) / class definitions
• the code of the class
• the code of the initial specification / test program
all into a single file, separated by a ruling off comment:
  // ---------------------------------------------------------

This allows the API to be developed and fine tuned without constant frame / window switching, with delegates learning where extra code members are needed as they write. And then the code can be saved in three different directions:
• the header file
• the code definition file (with a #include of the header)
• the sample program / test file (again with a #include of the header).

See that in source:
All together - [here]
or
Sample and test program - [here]
Definitions of API - [here]
Code of object methods - [here]