Design Pattern Examples
Overview of object-oriented design patterns
c/Flyweight_Exercise.h File Reference

Declaration of the Flyweight_Exercise() function as used in the Flyweight Pattern. More...

This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Macros

#define __FLYWEIGHT_EXERCISE_H__
 

Functions

void Flyweight_Exercise (void)
 Example of using the Flyweight design pattern.
 

Detailed Description

Declaration of the Flyweight_Exercise() function as used in the Flyweight Pattern.

Definition in file c/Flyweight_Exercise.h.

Macro Definition Documentation

◆ __FLYWEIGHT_EXERCISE_H__

#define __FLYWEIGHT_EXERCISE_H__

Definition at line 9 of file c/Flyweight_Exercise.h.

Function Documentation

◆ Flyweight_Exercise()

void Flyweight_Exercise ( void  )

Example of using the Flyweight design pattern.

The Flyweight pattern is used when a large object needs to be represented by a much lighter weight class, possibly multiple instances of said light-weight class.

In this example, a large object is represented by a so-called "big resource" (a two-dimensional array of text characters) containing multiple images, one associated with each flyweight class. Flyweight classes that represent offset into the big resource, along with position and velocity, are attached to the big resource image so they all share the same image but have different positions and velocities. The image is rendered to a display area through the Flyweight class. The Flyweight class instances then have their positions updated, bouncing off the edges of the display area 60 times a second. This continues for 1000 iterations or until a key is pressed.

Definition at line 346 of file Flyweight_Exercise.c.

References _Flyweight_ClearDisplay(), _Flyweight_GenerateBigResource(), _Flyweight_GenerateDisplay(), _Flyweight_GenerateFlyweightClasses(), _Flyweight_MoveFlyweights(), _Flyweight_RenderFlyweights(), _Flyweight_ShowDisplay(), BigResourceManager_Clear(), checkforkey(), disableinputecho(), Display_Destroy(), enableinputecho(), Flyweight_ImageList_Clear(), getcursorposition(), readkey(), setcursorposition(), and sleep().