Business object Calling Another Business Object

Business object Calling Another Business Object

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


devbanana posted on Friday, July 20, 2007

;Hello,

 

What is the best way to call another business object from a business object, say from one of the DataPortal_xx methods?

 

Kind of like what the Resource class does with its Exists method in the example.

 

I have a business object Report, that needs to call ReportList to search for a certain bit of data. I just want to call the fetch for this list. Is this possible?

RockfordLhotka replied on Friday, July 20, 2007

Business objects can interact with each other in the same way the UI interacts with the objects.

In other words, your Report object can get an instance of ReportList by calling the ReportList.GetList() factory method (or whatever you called it).

This works on the client or app server - the functionality is location transparent.

devbanana replied on Friday, July 20, 2007

Hi,

 

Yeah I know that works; but then why did the exists command example in project tracker do it using DataPortal, passing the type to the generic method?

 

The reason I wanted to do it this way more than anything is that the GetReportList method of the ReportList assumes it is the top of the business layer, and so if something goes wrong it basically handles the exception and throws a UiException for the UI layer to handle, which is much more generic than the business exception. This is only done however in the GetReportList method and not in the fetch itself, since I view the fetch as the data layer.

 

So I would've loved just to call the DataPortal_Fetch method of the ReportList object somehow. Is it possible?

RockfordLhotka replied on Friday, July 20, 2007

You absolutely should NOT call DataPortal_XYZ methods directly. That would bypass the data portal and you’d lose all the benefits of the data portal.

 

You can call the data portal directly, but you’d need access to the appropriate Criteria object to do that. Typically a Criteria class is private (and it should be), so you can’t call the data portal externally.

 

I would criticize my own code in the case of Exists(). It should call a factory method from ExistsCommand rather than calling the data portal directly. That is an example of me being in a hurry and writing some sloppy code.

 

In your case, I suggest creating a second factory method on ReportList – make it Friend/internal in scope so you don’t confuse the UI developers and you should be fine.

 

Rocky

devbanana replied on Friday, July 20, 2007

Hi,

 

Oh of course I wasn't going to call the DataPortal_Fetch method directly, just was talking about doing what you did with the command object.

 

But I like your idea better indeed. Thank you for the suggestion.

Copyright (c) Marimer LLC