DEPARTMENT OF COMPUTING

CS 3005: Programming in C++

Factories

Introduction

In object oriented programming, a factory is a class that can create instances of other classes. It is a common pattern to create a factory that is capable of constructing an instance from a class within a class hierarchy. The object returned is a polymorphic instance of the base class.

Read more at the Wikipedia article on the factory method.

Assignment

In this assignment, you will create factory classes for the waveform and envelope hierarchies.

enum

An enumeration (enum in C++) is a user defined type allowing the user to specify symbols to represent a group of related unique constants.

The syntax is as follows:

enum TypeNameYouDeclare { CONSTANT1, CONSTANT2, ... };

This declares a new type TypeNameYouDeclare, with possible values CONSTANT1, CONSTANT2, etc.

Class Data Members

A class data member is declared with the static modifier. For example:

class X {
public:
  const static int ONE;
};

A class data member is initialized like a global variable in the implementation file. For example:

const static int X::ONE = 1;

Class Methods

A class method can be called from the class, or from an instance of the class. It is allowed to use class data members, but there is no this pointer to an instance, so instance data members and methods are not accessible.

Simple example of declaration in the header file:

class X {
public:
  static int add(int a, int b);
};

Then in the implementation file:

static int X::add(int a, int b) {
  // not allowed to access instance data members
  return a + b;
}

Programming Requirements

Create library-waveform/WaveformFactory.{h,cpp}

WaveformFactory Class

Data Members:

The WaveformFactory class will not have any private data members. The class will not need to be instantiated.

public Class Data Members:

public Enumerations:

public Methods:

Update library-waveform/Makefile

Add WaveformFactory.{h,cpp} in the appropriate places to add them to the library and install the header file.

Create library-envelope/EnvelopeFactory.{h,cpp}

EnvelopeFactory Class

Data Members:

The EnvelopeFactory class will not have any private data members. The class will not need to be instantiated.

public Class Data Members:

public Enumerations:

public Methods:

Update library-envelope/Makefile

Add EnvelopeFactory.{h,cpp} in the appropriate places to add them to the library and install the header file.

Additional Documentation

TBA

Grading Instructions

To receive credit for this assignment:

Extra Challenges (Not Required)

TBA

Last Updated 10/23/2024