A practical example

To demonstrate the practical aspects of implementing a flyweight pattern, I have put together a simple application that stores and displays information about customers. It is implemented as the Flyweight and is stored in the Flyweight folder.

A customer is represented by an ICustomer interface, defined in the Customer unit as shown here:

type  TPersonalInfo = record  public    ID: integer;    Name: string;    Address : string;    constructor Create(const AName, AAddress: string);  end;   ICustomer = interface ['{1AE32361-788E-4974-9366-94E62D980234}']    function GetCompanyInfo: TCompanyInfo;    function GetPersonalInfo: TPersonalInfo;    property CompanyInfo: TCompanyInfo read GetCompanyInfo; property PersonalInfo: TPersonalInfo read GetPersonalInfo; ...

Get Mastering Delphi Programming: A Complete Reference Guide now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.