Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Software
- {
- friend class SoftwareProducer;
- SoftwareProducer* m_producer;
- int m_key;
- // Only producers can produce software
- Software(SoftwareProducer* producer) : m_producer(producer) { }
- public:
- void buy()
- {
- m_key = m_producer->next_key();
- }
- };
- class SoftwareProducer
- {
- friend class Software;
- public:
- Software* produce()
- {
- return new Software(this);
- }
- private:
- // Only software from this producer can get a valid key for registration
- int next_key()
- {
- return ...;
- }
- };
- class Software {
- private:
- Software() : m_key(0) { /* whatever */ }
- public:
- void buy() { m_key = new_key(); }
- public:
- static Software *create() { return new Software; }
- private:
- static int new_key() { static int example_id = 1; return example_id++; }
- private:
- int m_key;
- };
- Software *soft = Software::create();
- soft->buy();
Add Comment
Please, Sign In to add comment