Alex Rivera | Logout

Should a c# class generate instances of itself?

Asked 2008-11-02T00:18:43.727
14

I have a class that defines a CallRate type. I need to add the ability to create multiple instances of my class by reading the data from a file.

I added a static method to my class CallRate that returns a List<CallRate>. Is it ok for a class to generate new instances of itself by calling one of its own constructors? It works, I just wonder if it's the proper thing to do.

List<CallRates> cr = CallRates.ProcessCallsFile(file);
Edit
Report

1 Answer

5

Sure that's fine, even encouraged in some instances. There are several design patterns that deal with object creation, and a few of them do just what you're describing.

answered 2008-11-02T00:24:52.233

Your Answer