Design of singleton sub-type?

J

Joseph Turian

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
 
V

veldwolf

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;
};
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,432
Messages
2,571,681
Members
48,796
Latest member
Greg L.

Latest Threads

Top