Monday, August 2, 2010

Assignment : Case Study 7

We have a neatly written application and all important classes are derived from one Abstract class and uses Factory method for creation. We are witnessing some performance issues so we need to find the time to execute the important functions of these classes and also log the in and out parameter. The log of parameters and time taken to execute the calls is independent, can be switched on and off separately. I suggested that we can change all these 20 classes with some #def code and put the relevant code. My Architect says that he doesn’t want to build unnecessary dependencies in main code and these can be selectively turned on customer side to fine tune the performance. Please suggest.

3 comments:

  1. Well I think we should use decorator pattern here as want the logging behaviour on the top of the existing class without modifying the class it self. We may have Decorator class derived from the given abstract class and can have two concrete decorator say logIn&Out and logTime and in client code we may call decorators depending upon some preference file.

    ReplyDelete
  2. I agree with Anurag we can decoreate the important functions to log.


    class AbstractImageLib
    {
    public:
    virtual void getRawImage() = 0;
    virtual void getJpegImage() = 0;
    virtual void doSomeProcessing() = 0;
    };
    class ImageLib: public AbstractImageLib
    {
    public:
    virtual void getRawImage();
    virtual void getJpegImage();
    virtual void doSomeProcessing();
    };

    class ImageLibDecorator: public ImageLib
    {
    ImageLibDecorator(ImageLib *decoratedImageLib) {m_decoratedImageLib = decoratedImageLib;}

    virtual void getRawImage()
    {
    cout<<"getRawImage called";
    m_decoratedImageLib->getRawImage();
    cout<<"getRawImage returned";
    }
    private:
    ImageLib * m_decoratedImageLib;
    }

    ReplyDelete
  3. class IAbstract
    {
    method1() =0;
    method2() =0;
    method3() = 0;
    };

    class Logger;

    class LoggerDecorator:IAbstract
    {
    Logger *m_pLogInst;
    IAbstract *pInstTobeDecorated;

    LoggerDecorator(IAbtsract *pConInst)
    {
    m_pLogInst = new Logger;
    m_pInstTobeDecorated = pConInst;
    }

    method1()
    {
    m_pLogInst->Log("TimeIn");
    m_pInstTobeDecorated->method1()'
    m_pLogInst->Log("TimeOut");
    }

    };

    ReplyDelete