Design Pattern Examples
Overview of object-oriented design patterns
Flyweight_Class Class Reference

Associates a context with a big resource. More...

Collaboration diagram for Flyweight_Class:
Collaboration graph

Public Member Functions

void Render (List< char[]> display, int offset_x, int image_width, int image_height, int position_x, int position_y)
 Render the image associated with this flyweight instance into the given display at the given position.
 

Package Functions

 Flyweight_Class (BigResource resource, Flyweight_Context context)
 Constructor (accessible only to the class factory).
 

Properties

Flyweight_Context Context [get, set]
 Retrieve or set the context for this class instance.
 
int ImageWidth [get]
 Retrieve the "image" width from underlying big resource.
 
int ImageHeight [get]
 Retrieve the "image" height from underlying big resource.
 

Private Attributes

BigResource _resource
 The big resource being referenced by this flyweight class. In C#, a class is always a reference to an instance of the class so we take advantage of that here. In other languages, this would be a pointer to the big resource or a handle from which a pointer could be obtained.
 
Flyweight_Context _context
 The context associated with this class. The calling entity uses this context to manipulate the flyweight class.
 

Detailed Description

Associates a context with a big resource.

Definition at line 65 of file Flyweight_Class.cs.

Constructor & Destructor Documentation

◆ Flyweight_Class()

Flyweight_Class ( BigResource  resource,
Flyweight_Context  context 
)
inlinepackage

Constructor (accessible only to the class factory).

Parameters
resourceThe resource being represented by this class. This takes advantage of the fact that C# classes are always passed by reference so no actual copying of the resource is done.
contextA Flyweight_Context instance containing the context for this Flyweight_Class instance.

Definition at line 91 of file Flyweight_Class.cs.

References Flyweight_Class._context, and Flyweight_Class._resource.

Member Function Documentation

◆ Render()

void Render ( List< char[]>  display,
int  offset_x,
int  image_width,
int  image_height,
int  position_x,
int  position_y 
)
inline

Render the image associated with this flyweight instance into the given display at the given position.

Parameters
displayA list of character arrays representing the display.
offset_xOffset from left edge of big resource to the left edge of the image to render.
image_widthWidth of image to render.
image_heightHeight of image to render.
position_xleftmost position within the display to place the upper left corner of the image,
position_ytopmost position within the display to place the upper left corner of the image.

Note that although this class has access to the context, it really shouldn't so as to keep a loose coupling between the context and this class. Therefore, the entity calling Render() will pass the position in as parameters even though that position is likely coming from the context.

Definition at line 165 of file Flyweight_Class.cs.

References Flyweight_Class._resource, and BigResource.Render().

Referenced by Flyweight_Exercise._Flyweight_RenderFlyweights().

Member Data Documentation

◆ _context

Flyweight_Context _context
private

The context associated with this class. The calling entity uses this context to manipulate the flyweight class.

Definition at line 80 of file Flyweight_Class.cs.

Referenced by Flyweight_Class.Context(), Flyweight_Class.Flyweight_Class(), Flyweight_Class.ImageHeight(), and Flyweight_Class.ImageWidth().

◆ _resource

BigResource _resource
private

The big resource being referenced by this flyweight class. In C#, a class is always a reference to an instance of the class so we take advantage of that here. In other languages, this would be a pointer to the big resource or a handle from which a pointer could be obtained.

Definition at line 74 of file Flyweight_Class.cs.

Referenced by Flyweight_Class.Flyweight_Class(), Flyweight_Class.ImageHeight(), BigResource.ImageHeight(), Flyweight_Class.ImageWidth(), BigResource.ImageWidth(), Flyweight_Class.Render(), and BigResource.Render().

Property Documentation

◆ Context

Flyweight_Context Context
getset

Retrieve or set the context for this class instance.

Definition at line 101 of file Flyweight_Class.cs.

Referenced by Flyweight_Exercise._Flyweight_MoveFlyweights(), and Flyweight_Exercise._Flyweight_RenderFlyweights().

◆ ImageHeight

int ImageHeight
get

Retrieve the "image" height from underlying big resource.

Definition at line 133 of file Flyweight_Class.cs.

Referenced by Flyweight_Exercise._Flyweight_MoveFlyweights(), and Flyweight_Exercise._Flyweight_RenderFlyweights().

◆ ImageWidth

int ImageWidth
get

Retrieve the "image" width from underlying big resource.

Definition at line 117 of file Flyweight_Class.cs.

Referenced by Flyweight_Exercise._Flyweight_MoveFlyweights(), and Flyweight_Exercise._Flyweight_RenderFlyweights().


The documentation for this class was generated from the following file: