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

Generic or Non-Generic?

P: n/a
Hi all,
I´m creating a factory class and I don´t know if it´s better to create it
with Generics or not. The basic funcionality would be:
public static class DalcFactory<T>

public static T Instantiate()

{

if (typeof(T).Name.Equals("Example"))

return (T) Assembly.LoadFrom(...).CreateInstance(...);

}

Without generics, the class would contains inumerous static methods,
GetObject1, GetObject2, GetObject3, and others. With Generics, I would use
just one method, Instantiate, as above.

I want to know wich one is better, in performance.

Thanks!

André
Sep 26 '06 #1
Share this Question
Share on Google+
1 Reply


P: n/a
If you use separate methods, the type will be identified at compile time
instead of at runtime, so you'll save a bit of work.

I think that the work to identify the type is relatively small compared
to the work of creating the object, though, so I'd suggest that you go
for the method that gives the nicest code.

André Nobre wrote:
Without generics, the class would contains inumerous static methods,
GetObject1, GetObject2, GetObject3, and others. With Generics, I would use
just one method, Instantiate, as above.

I want to know wich one is better, in performance.
Sep 27 '06 #2

This discussion thread is closed

Replies have been disabled for this discussion.