Where to put my code?

  • Thread starter Thread starter thechaosengine
  • Start date Start date
T

thechaosengine

Hi all,

I have a very simple issue that I often come up against. I'm just wondering
what the common consensus is on dealing with it.

I have a Project class, that has amongst other properties, an int representing
a ProjectManager. The question is what should I do when I want more details
on the project manager?

I have a couple of options:

I could add extra properties to the Project class so that as well as offering
an id, I can also get the project managers name and email perhaps.

Or, I can take that I'd at runtime and submit another seperate query to get
details on the project manager.

The pro of adding extra properties is that it is much easier to do a common
operation and doesnt require another sql query to be executed because I'd
just get the projman's details when getting the Projects details.

The disadvantage of this is that it breaks encapsulation. Purists believe
that the project managers details should only be contained in a ProjectManager
object.

I'm sure you've all come accross this scenario so I'm just wondering what
everyone else does.

Many thanks to anyone who can advise.

Kindest Regards

tce
 
Hi, tce,

If you're not familiar with it, check out Martin Fowler's "Refactoring:
Improving the Design of Existing Code", and his website
www.refactoring.com.

I think his answer would be: keep your code and your coding abilities
in such a state that it doesn't much matter where the code goes,
_initially_, then when you realize it's not where it belongs, move it,
safely (because you have comprehensive unit tests to assure that such
changes don't affect its behavior). And I guess my answer is the same.
Peace,
--Carl
 
Back
Top