Overuse of Reflection

Overuse of Reflection

Old forum URL: forums.lhotka.net/forums/t/9.aspx


Ruckus posted on Friday, May 05, 2006

I am using CSLA 2.0 as the foundation for a major enterprise scale application and I have some concerns about the amount of reflection used. Wouldn't it make more sense to take an interface driven approach to the DataPortal instead of using reflection on each DB call?

RockfordLhotka replied on Friday, May 05, 2006

This is a pretty common question, and I answered it here for CSLA .NET 1.x.

The answer remains fundamentally the same for version 2.0. Though in version 2.0 the use of reflection is (I think) even more justified because it allows the business developer to write strongly typed DataPortal_XYZ methods. An interface-based approach would force a return to the 1.x approach of passing in parameters of type object and then manually casting them.

All that said, people have altered CSLA .NET to replace the reflection calls with an interface in the past, and I'm sure that change will be done in the future as well. But I don't anticipate making such a change to the core framework itself, because I like the following:

  1. the UI developer doesn't see the data persistence interface
  2. strongly typed parameters for DataPortal_XYZ methods
  3. you aren't forced to implement methods you don't usually use or care about (like the pre-, post- and error handling methods in almost all objects, and various other DataPortal_XYZ methods in other types of objects)
  4. this is actually a subset of a broader concept called an object portal, and I have a personal affinity for that concept Smile [:)]

 

Ruckus replied on Friday, May 05, 2006

Okay, thanks for the explanation. Since you have already done the research I think I will leave well enough alone and quit trying to optimize prematurely.

ryancammer replied on Friday, May 05, 2006

Rules of optimization:

1. Don't
2. Not yet

Copyright (c) Marimer LLC