Should we pass objects or discrete properties to methods?

T

tmonico

Hi all,

I have a general OO question that I'd like to pose. Here's the
scenario.

Three classes, one business object class and two worker classes. The
worker classes need data from the business object class. In your
opinion is it better to have the worker classes take the business
object as a parameter and access the business objects data through the
business object public interface or is it better to completely decouple
the business object from the worker calsses and pass in discrete
parameters to the worker object methods?

For example:

WokerObject.DoSomethig(BusinessObject)
{
Do someThing with BusinessObject.PropertyA
Do someThing with BusinessObject.PropertyB
Do someThing with BusinessObject.PropertyC
}

or

WokerObject.DoSomethig(BusinessObject.PropertyA,
BusinessObject.PropertyB, BusinessObject.PropertyC)
{
Do someThing with PropertyA
Do someThing with PropertyB
Do someThing with PropertyC
}

The first method is cleaner in my opinion. It has a simplified
interface, however WorkerObject is now coupled to BusninessObject. In
the second method the interface is busier and not as clean, but
WorkerObject and BusinessObject are not coupled.

So what are the Pros and Cons of each approach? Which do you think is
better and why? I originally stated that there were two WorkerClasses.
I did this because I'd like to know if having many WorkerObjects
classes that use BusinessObject would affect your opinion.

I look forward to your insight.
 

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
473,772
Messages
2,569,593
Members
45,111
Latest member
KetoBurn
Top