Best way to create a collection of a class

Posted by smartins on Stack Overflow See other posts from Stack Overflow or by smartins
Published on 2010-04-18T19:35:39Z Indexed on 2010/04/18 19:53 UTC
Read the original article Hit count: 162

Filed under:

I'm trying to create some classes that allow me to retrieve and manipulate a set of backups my application will create and manage.

I've come up with the following code (not tested yet), but I'm not sure if it's the best way of accomplishing this or if there's any easier/better way. I'm using Delphi 2010.

I have a class that holds the backup details (TBackupItem), then I need to have a class that will hold a collection of TBackupItem and finally I'll have a class that manages the reading and writing of backups and also exposes a property that accesses the collection of TBackupItem.

type
  TBackupItem = class
  private
    FBackupProgram: string;
    FBackupProgramVersion: string;
    // There are more variables and properties but for the sake of simplicity I've listed only two
  public
    property BackupProgram: string read FBackupProgram write FBackupProgram;
    property BackupProgramVersion: string read FBackupProgramVersion write FBackupProgramVersion;
  end;

  TBackupsList = class(???)
  private
    // This class will hold a list of TBackupItem. What should I use to accomplish this?
  end;

  TBackupsManager = class(TObject)
  private
    FBackups: TBackupsList;
  public
    property Backups: TBackupsList read FBackups write FBackups;
  end;

Do you guys have any comments and/or examples on the best way of accomplishing this?

Thanks!

© Stack Overflow or respective owner

Related posts about delphi