title: Friends, Abstract classes and Factory pattern
body: <p>Good day to you all...</p>
  
  <p>I'm working on a complex project on my company which I use some wringled Factory Design pattern in the project. Omiting the details; I have some classes (I call them "Devices") which can only be created by "Readers":</p>
  
  <pre><code>class DeviceBase // this is a virtual base class
  {
    public:
     //some stuff
     friend class ReaderBase; // this is OK and necessary I guess?
    private:
     DeviceBase(); // cannot create a device directly
     //some more stuff
  }
  
  class Device1: public DeviceBase // some extended device
  {
    public:
     //some stuff 
    private:
     //some more stuff
  }
  
  class Device2: public DeviceBase  // some other extended device
  {
    public:
     //some stuff
  
    private:
     //some more stuff
  }
  </code></pre>
  
  <p>Now the "Reader", which happens to be factory for devices:</p>
  
  <pre><code>class ReaderBase
  {
    private:
      DeviceBase[] _devices; // to keep track of devices currently "latched"
    public:
      // some other methods, getters-setters etc ...
  
      // this method will create the "Devices" :
      virtual bool PollforDevice ( DeviceType, timeout) = 0; 
  
  }
  </code></pre>
  
  <p>Now, this is my factory class; but it's (as you can see) pure virtual. I have special Readers inherit from this one:</p>
  
  <pre><code> class InternalReader: public ReaderBase
   {
     public:
       // define other inherited methods by specifics of this reader
       bool PollforDevice( DeviceType dt, timeout ms)
       {
           switch(dt)
           {
             case Device1: { /* create new device1 and attach to this reader */ } break;
             case Device2: { /* create new device2 and attach to this reader */ } break;
           }
           // show goes on and on...
       }
   }
  
   class ExternalReader: public Reader
   {
     public:
       // define other inherited methods by specifics of this reader
       bool PollforDevice( DeviceType dt, timeout ms)
       {
           switch(dt)
           {
             case Device1: { /* create new device1 and attach to this reader */ } break;
             case Device2: { /* create new device2 and attach to this reader */ } break;
           }
           // show goes on and on...
       }
   }
  </code></pre>
  
  <p>The reason I use this pattern is: I'm writing for a system that can have multiple of these "readers" attached at the same time and I must use them all at the same time. </p>
  
  <p>And these "Devices": I can make theirs constructor public too, and everyone would be happy; but I want to make sure that they are not created by the code writers themselves (to make sure other coders of it)</p>
  
  <p>Now the questions:</p>
  
  <ol>
  <li>Should I explicitly declare in every "Device" that ReaderBase is a friend? Or just declaring at the base "DeviceBase" should be enough?</li>
  <li>Should I explicitly put in every "Device" that the "Readers" inherited from the "ReaderBase" are also friends of these devices, or just putting ReaderBase is enough?</li>
  <li>Instead of making whole "ReaderBase" class a friend, can I (and should I) just make the member method "PollforDevice" a friend? Knowing that it's a pure virtual method, would that make inherited copies friends as well?</li>
  </ol>
  
  <p>I'm sorry that the question is a very long one, but I just want to make it clear.</p>
  
  <p>Thanks in advance...</p>