Monday, August 2, 2010

Assignment: Case Study 8

We have an inhouse C++ SDK that exposes fixed interface to read and write JPEG, TIFF & PDF files. There is a sniffer class that tells us which type of file type it is and based on that we create the instance of FileFormat (JPPEG, TIFF, PDF) class using a factory. The problem is that for PNG we have taken open source implementation and it doesn’t conform to our existing C++ interface. Please suggest what you believe is the best approach.

5 comments:

  1. Is it possible to add PNG file type also to the existing factory since we already have the implementation for the same? Pls don't ask me the code, i don't know... :)

    ReplyDelete
  2. We can have a PNG class derived from the base class as in other cases and wrap the PNG library functionality with in this class i.e. having PNG library object/pointer as an member varaiable of this class and use this object to do the actual tasks basically providing a adapter class as per new hierarchy of ours and underlying delegate the tasks to PNG library object/pointer.

    ReplyDelete
  3. Wrap an existing class with a new interface.
    Adapter design pattern.

    ReplyDelete
  4. Add PNG class to existing factory.
    So now based on type we can get PNG obj,
    Call Read & Write of PNG class( as SDK is not supporting for PNG type)

    ReplyDelete
  5. This is a case of Adapter.
    class IInterface
    {
    ReadImage() = 0;
    WriteImage() = 0;
    }
    class PNGInterface : IInterface
    {
    private:
    PNGAdaptor *m_pPNGAdaptor;
    public:
    ReadImage()
    {
    m_pPNGAdaptor->ReadImage();
    }
    WriteImage()
    {
    m_pPNGAdaptor->WriteImage();

    }

    };
    class PNGAdapter
    {
    private:
    PNGImpl *m_pImpl;
    public:
    ReadImage()
    {
    m_pImpl->ReadPNG();

    }

    WriteImage()
    {
    m_pImpl->WritePNG();
    }

    }

    ReplyDelete