- 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 Real Network Link
Listing 4 illustrates an entity called RealLink that models a real network link. As you can see, it’s derived from the GenericLink class.
Listing 4 A concrete network link entity.
#define BUFFER_LENGTH class RealLink : public GenericLink { public: explicit RealLink(char*, char*, char*, char*, char*, GenericLinkContext*); virtual ~RealLink(void); void GetAllIPAddresses(char*); private: char* technologyType; };
The constructor for RealLink supplies the data needed by the base class and also provides the technologyType. The member function GetAllIPAddresses() allows us to view the IP address range used by this link in the network.
Starting with the generic link, let’s look at the implementation of all these interfaces. Then we’ll be ready to see the complete code in action.