Data Model: Mp3File
- Abstract base classes (Section 6.3)
- Multiple inheritance (Section 23.3)
Figure 25.3 shows a UML diagram of the data model for our MP3 player application, at the lowest level.
Figure 25.3. Initial data model
Mp3Song is an abstract class (which is why it is italicized in the UML diagram). This interface is meant to describe a common set of features for different implementations of the Mp3Song interface.
Example 25.1. ../src/libs/filetagger/mp3song.h
#ifndef _MP3SONG_H
#define _MP3SONG_H
#include |
Note also that there is a getTRackTime() function but no setTrackTime() method. This is because m_trackTime is a calculated value, a read-only property. Derived classes will override this method and return the actual time of the song.
The Assignment
- Define a class Mp3File that implements the Mp3Song interface but allows you to store and retrieve the values in data members.
- Define a PlayListModel, a collection of Mp3Songs. Reuse a QList
to hold pointers to heap Mp3File objects. - Write the implementations to the classes described in the UML diagram in Figure 25.3. This includes data members, getters and setters, and a toString() method for Mp3File.
Категории |