Abstract Factory as a holder for different representation
Hi All
I am working on a Stock Exchange related program. Because I want, my
program be independent from specific market convention, I designed a
class hierarchy for market and a class hierarchy for Market Factory.
Market Factory is like Abstract Factory:
// Mrkt.h
struct Mrkt {
public:
class AbsIndividual {
public:
virtual ~AbsIndividual() =0 {}
};
virtual ~Mrkt() =0;
};
struct IranMrkt : Mrkt {
std::string Name;
struct IndividualBaseInfo : Mrkt::AbsIndividual {
std::string Nmae;
std::string FamilyName;
};
struct InvestmentCompBaseInfo : Mrkt::AbsIndividual {
std::string Name;
std::string ExecutiveMngr;
};
};
// MrktFactory.h
struct MrktFactory {
public:
virtual Mrkt::AbsIndividual* MakeIndividual() const =0;
virtual Mrkt::AbsIndividual* MakeInvestmentComp() const =0;
virtual ~MrktFactory() { }
};
struct IranMrktFactory : MrktFactory {
Mrkt::AbsIndividual* MakeIndividual() const {
return new IranMrkt::IndividualBaseInfo();
}
Mrkt::AbsIndividual* MakeInvestmentComp() const {
return new IranMrkt::InvestmentCompBaseInfo();
}
};
int main()
{
auto_ptr<MrktFactory> g_MrktFactory(new IranMrktFactory());
}
Up to here, my program is OK and everything is fine. But there is a
lot ot thing that I want to represent in specific market as a nested
class or object. For example, in IRAN, the market is opened at 9:00 am
and is closed at 12:30 pm. In IRAN, we use Solar system for
representing date and Thursday and Friday are holiday, so I should
have something like this:
struct IranMrkt : Mrkt {
struct Calendar {
// Calendar stuff
class IranianDate {
// ...
};
}
// ...
};
My problem is: after creating Factory in main and after it is clear
that program bound to IranMrkt, I want to write the following code:
int main()
{
auto_ptr<MrktFactory> g_MrktFactory(new IranMrktFactory());
IranMrkt::Calendar Cal;
// Stock Exchange Bell
pair<IranMrkt::Calendar::IranianTime,
IranMrkt::Calendar::IranianTime> theBell;
}
I want, it to be plug and play not ad-hoc. I want to retrieve the
class from created factory.
Would you please help me and offer your solution?
Regards,
S. Amrollahi