By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,347 Members | 2,120 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,347 IT Pros & Developers. It's quick & easy.

Design of singleton sub-type?

P: n/a
Hi all,

I'm trying to refactor some code and wanted design advice.

Here's where I'm starting:
I have a class called Classifier which is based upon the singleton
pattern:
class Classifier {
public:
const Classifier& get(type t);
private:
Classifier(type t);
static map<type, Classifier> _map;
};
When you Classifier::get(t), it retrieves the corresponding Classifier
from _map, constructing it if necessary.
I want to make a subclass BuildClassifier, which has a ::get method
that retrieves a *non*-const BuildClassifier, and each BuildClassifier
object will contain some extra needed data.

My question is, if someone calls Classifier::get(t), I now want to
return the BuildClassifier object associated with t (a const-version,
naturally). How can I do that?

Joseph

Apr 11 '06 #1
Share this Question
Share on Google+
1 Reply


P: n/a
I think you may change the member function's (const Classifier&
get(type t)) declare in Classifier,i think below code will work as your
expect:
class Classifier {
public:
virtual const Classifier& get(type t);
private:
Classifier(type t);
static map<type, Classifier> _map;
};

Apr 11 '06 #2

This discussion thread is closed

Replies have been disabled for this discussion.