- 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
A Generic Network Link
The first entity we need to model is that of a network link. At the top of my inheritance hierarchy is a class that represents any network link type, whether the link technology is MPLS, ATM, frame relay, etc. That is, I need a generic link class (called GenericLink), as shown in Listing 2.
Listing 2 Generic network link.
class GenericLink { public: explicit GenericLink(GenericLinkContext*, char*, char*, char*, char*); virtual ~GenericLink(void); protected: GenericLinkContext* linkContext; public: int mySlotNumber; private: char* NodeA; char* NodeB; char* InterfaceA; // Each interface can support many IP addresses char* InterfaceB; // Each interface can support many IP addresses };
The private data members in GenericLink describe the location of a link in the network—the link joins two interfaces on two nodes. We want to add IP addresses to this data, and the protected data member GenericLinkContext is used for this purpose, as I’ll explain in the next section. We’ll also see the significance of the public data member mySlotNumber.