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

Represents a manager for big resources. Also provides the class factory for the Flyweight_Class instances that are associated with a particular big resource. More...

Collaboration diagram for BigResourceManager:
Collaboration graph

Static Public Member Functions

static int AddResource (List< string > rawResource)
 Add a new big resource and return the ID of the resource.
 
static ? Flyweight_Class CreateFlyweight (int bigResourceId, Flyweight_Context context)
 Create a new instance of the Flyweight_Class associated with the given big resource and a context, in this case an X,Y position.
 

Static Package Functions

static ? BigResource FindResource (int resourceId)
 Retrieve the BigResource corresponding to the specified ID.
 

Static Private Member Functions

static int GetNextResourceId ()
 Retrieve the next resource ID that can be used.
 

Static Private Attributes

static List< BigResource_resources = new List<BigResource>()
 A list of all big resources managed by this class.
 
static int _nextResourceId = 1
 The next ID to assign a raw resource for management.
 

Detailed Description

Represents a manager for big resources. Also provides the class factory for the Flyweight_Class instances that are associated with a particular big resource.

Note: The raw resource is provided by the caller and an ID is then associated with it. The ID is returned to the caller who then passes that ID to the Flyweight_Class factory along with a context.

In the exercise, only one big resource is ever created so this class is likely overkill for an example but it fully shows the architectural context in which a flyweight class is utilized.

Definition at line 350 of file Flyweight_Class.cs.

Member Function Documentation

◆ AddResource()

static int AddResource ( List< string >  rawResource)
inlinestatic

Add a new big resource and return the ID of the resource.

Parameters
rawResourceThe resource to add.
Returns
Returns the ID of the new big resource added to the manager.

Definition at line 378 of file Flyweight_Class.cs.

References BigResourceManager._resources, and BigResourceManager.GetNextResourceId().

Referenced by Flyweight_Exercise._Flyweight_GenerateBigResource().

◆ CreateFlyweight()

static ? Flyweight_Class CreateFlyweight ( int  bigResourceId,
Flyweight_Context  context 
)
inlinestatic

Create a new instance of the Flyweight_Class associated with the given big resource and a context, in this case an X,Y position.

Parameters
bigResourceIdID of the big resource to associate with.
contextA Flyweight_Context instance containing the context for the desired Flyweight_Class instance.
Returns
A new instance of the Flyweight_Class. Returns null if the big resource was not found.

Definition at line 417 of file Flyweight_Class.cs.

References BigResource.CreateFlyweight(), and BigResourceManager.FindResource().

Referenced by Flyweight_Exercise._Flyweight_GenerateFlyweightClasses().

◆ FindResource()

static ? BigResource FindResource ( int  resourceId)
inlinestaticpackage

Retrieve the BigResource corresponding to the specified ID.

Parameters
resourceIdID of the big resource to find.
Returns
Returns a BigResource object corresponding to the specified ID. Returns null if there is no corresponding IBigResource object.

Definition at line 393 of file Flyweight_Class.cs.

References BigResourceManager._resources, and BigResource.ResourceId.

Referenced by BigResourceManager.CreateFlyweight().

◆ GetNextResourceId()

static int GetNextResourceId ( )
inlinestaticprivate

Retrieve the next resource ID that can be used.

Returns
The next resource ID.

Definition at line 366 of file Flyweight_Class.cs.

References BigResourceManager._nextResourceId.

Referenced by BigResourceManager.AddResource().

Member Data Documentation

◆ _nextResourceId

int _nextResourceId = 1
staticprivate

The next ID to assign a raw resource for management.

Definition at line 360 of file Flyweight_Class.cs.

Referenced by BigResourceManager.GetNextResourceId().

◆ _resources

List<BigResource> _resources = new List<BigResource>()
staticprivate

A list of all big resources managed by this class.

Definition at line 355 of file Flyweight_Class.cs.

Referenced by BigResourceManager.AddResource(), and BigResourceManager.FindResource().


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