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


class Mp3Song {

 static QStringList fields();
 virtual ~Mp3Song();

 virtual QString getGenre() const =0;
 virtual QString getArtist() const =0;
 virtual QString getAlbumTitle() const =0;
 virtual QString getTrackTitle() const =0;
 virtual QString getTrackNumber() const =0;
 virtual int getTrackTime() const =0;
 virtual QString getComment() const =0;
 virtual QString getPreference() const =0 ;
 virtual QString toString() const =0;
 virtual QString getUrl() const =0;
 virtual QString getFilename() const = 0;

 virtual void setPreference(const QString & newPref) = 0;
 virtual void setGenre (const QString& newGenre) =0;
 virtual void setArtist (const QString& newArtist) =0;
 virtual void setTrackNumber (const QString& trackNum) = 0;
 virtual void setTrackTitle (const QString& newTitle) = 0;
 virtual void setAlbumTitle (const QString& newAlbumTitle) = 0;
 virtual void setComment (const QString& newComment) = 0;
 virtual void setFilename (const QString& newFilename) =0 ;



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.

Part I: Introduction to C++ and Qt 4

C++ Introduction


Introduction to Qt



Inheritance and Polymorphism

Part II: Higher-Level Programming


Introduction to Design Patterns


Generics and Containers

Qt GUI Widgets


Validation and Regular Expressions

Parsing XML

Meta Objects, Properties, and Reflective Programming

More Design Patterns

Models and Views

Qt SQL Classes

Part III: C++ Language Reference

Types and Expressions

Scope and Storage Class

Statements and Control Structures

Memory Access

Chapter Summary

Inheritance in Detail

Miscellaneous Topics

Part IV: Programming Assignments

MP3 Jukebox Assignments

Part V: Appendices

MP3 Jukebox Assignments


MP3 Jukebox Assignments

An Introduction to Design Patterns in C++ with Qt 4
An Introduction to Design Patterns in C++ with Qt 4
ISBN: 0131879057
EAN: 2147483647
Year: 2004
Pages: 268 © 2008-2020.
If you may any questions please contact us: