MT 262 - Block 2 - Unit 3 - Designing Modular Programs
fellstrider.com - the logo!
Home| OU Study Rooms | MT262 Index | Block 2 - Structures
 
Designing Modular Programs

Purpose

A modular approach to programming separates the code into manageable chunks. Functions are one way to achieve this. A function should be designed to do a single task. Objects are introduced, enabling a reduction in the interaction of the program, reducing some of the possibilities of bugs.

Why modules?

Before any design can be commenced it is necessary to know what the input and output data is and what the relationship is between them. A further factor is a need to know how the operator is to interact with the system.

A modular solution to a problem should allow for the details of the implementation of each sub task to be modified without affecting the remaining sub tasks. The way in which different parts of the design communicate has to be carefully specified. This communication must remain unchanged if and when implementation changes are made.

Designing and testing of the processing code can be developed separately from the user interface.

Image representing relationship between modules and main program code

Objects

Combining data items with functions produces a data type structure known as objects. These can be regarded as active. Such active objects respond to requests to do something. The functions incorporated into the objects with the data items are called methods. Data tables will show the data items and their methods. These will make up a class definition.

Class Definition WarehouseType
Type Identifier Description
BinType Bins[6][10] Array of storage bins
String Store (InCode, InQuantity) Stores InQuantity of product InCode into Bins. Returns string giving location of bin used or error message if no bin available.
String Supply (OutCode, OutQuantity) Supplies OutQuantity of product OutCode from Bins. Returns string giving location(s) of bin(s) used and/or error message if order partly supplied

A variable of class WarehouseType defined above will be an object of that type.

Home| OU Study Rooms | MT262 Index | Block 2 - Structures
Move on to Unit 3 - Implementing classes

Valid CSS! Valid XHTML 1.0!

Comments, suggestions, ideas to
Stuart Banner