␡
- Protecting Valuable Resources
- Interfaces: Action-Packed Entities
- Configuring IP Addresses
- Solution Introduction and the Flyweight Pattern
- A Generic Network Link
- A Generic Network Link Context
- A Real Network Link
- The GenericLink Implementation
- The GenericLinkContext Implementation
- The RealLink Implementation
- Bringing the Code Together
- Conclusion
- Additional Reading
Like this article? We recommend
The GenericLink Implementation
Listing 5 is the implementation of the GenericLink class. The constructor is passed five parameters:
- A pointer to a GenericLinkContext object
- Two node pointers
- Two interface pointers
All of these parameters are stored and a free slot number is requested from the GenericLinkContext object.
Listing 5 Implementation of the generic link class.
GenericLink::GenericLink(GenericLinkContext* aLinkContext, char* nodeA, char* nodeB, char* ifA, char* ifB) { linkContext = aLinkContext; mySlotNumber = linkContext->GetNextFreeSlot(); NodeA = nodeA; NodeB = nodeB; InterfaceA = ifA; InterfaceB = ifB; } GenericLink::~GenericLink(void) { }
Now let’s look at the implementation of the GenericLinkContext class.