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 the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.