Source Package Layout

Synopsis:

Well designed source code is factored into many parts, some logical and some physical. Logical parts are things like functions, classes, and namespaces. Physical parts are the files and packages that we use to implement a program.

A C++ package usually consists of two files, a header file, like Str.h, and an implementation file, like Str.cpp. Each package should have a single responsibility. The Str package defines facility that allows users to easily manipulate null terminated arrays of characters, e.g., strings.

Package.h
Package.cpp

Each package consists of a Prologue (Package.h) - comments that:

Package declarations (Package.h): Package definitions (Package.cpp):

The package header is wrapped in a set of Preprocessor declarations that ensure that the header is only included once in each compilation unit - a cpp file with all of its included headers.

The test stub is wrapped in a pair of Preprocessor declarations that ensure that the main is compiled only if the package is being tested in a stand-alone mode.

Str Package

The string package is a good illustration of Package Layout and the C++ constructs used to build robust, efficient, and readable code. We will look at Str in detail in the next part of this course.

Str Package Source Code