My c++ SOA app has a concept of "session" that is used exchange data between services. In example its used for checking legality of some service A operations before executing session B which commits or rollback changes. Whatever.
I have 2 types of session modes: normal and what-if. Going further, I have different session, session for legality, session for assign, session for commit etc. This is a main problem. Legality session can be what-if or real etc.
How to fix that and avoid code duplication?
I can make a ISessionFactory interface and have WhatIfFactory and RealFactory implement it. Then I could make a ILegalitySession and make WhatIfLegalitySession and RealLegalitySession implement it. Then my factories would return appropriate objects.
It has 2 major problems. What if new mode will come? I will have to implement new factory and new classes for all sessions! What if new session type comes? I have to change both of factories...
Perhaps resign from 2 hierarhies and have whatIf sessions "decorate" real session? How can I localize the change?