Passing Business Objects as variables


Author
Message
choyt
choyt
StrataFrame Novice (98 reputation)StrataFrame Novice (98 reputation)StrataFrame Novice (98 reputation)StrataFrame Novice (98 reputation)StrataFrame Novice (98 reputation)StrataFrame Novice (98 reputation)StrataFrame Novice (98 reputation)StrataFrame Novice (98 reputation)StrataFrame Novice (98 reputation)
Group: Forum Members
Posts: 78, Visits: 246
Hi All

I want to pass a business object from one method to another. At first this seemed pretty simple but I'm not having much success except to do it as a generic object.  Am I missing something really dumb, is there another way or is this just it?

Public Sub DoIt(b as strataframeobject)

       ' in this example, i want to be able to pass different objects and load the results into cache

end function

Thansk!

Greg McGuffey
Greg McGuffey
Strategic Support Team Member (3.5K reputation)
Group: Forum Members
Posts: 2K, Visits: 6.6K
Well, it is actually that simple. However, if you want your method/function/sub to handle different types of business objects then you'd need to use BusinessLayer (Microfour.StrataFrame.Business.BusinessLayer).



I.e.



Sub DoIt(a As MyBO)




will work with MyBO objects only, were as



Sub DoIt(a As BusinessLayer)




will work with ANY business object.



Obviously what you do with the BO will determine which is better. Hope that helps! BigGrin

choyt
choyt
StrataFrame Novice (98 reputation)StrataFrame Novice (98 reputation)StrataFrame Novice (98 reputation)StrataFrame Novice (98 reputation)StrataFrame Novice (98 reputation)StrataFrame Novice (98 reputation)StrataFrame Novice (98 reputation)StrataFrame Novice (98 reputation)StrataFrame Novice (98 reputation)
Group: Forum Members
Posts: 78, Visits: 246
Thanks Greg

That helps. The problem I'm having now is that my FILL methods are custom created and are not being recognized in the sub. I will probably have to resort to late binding and if that is the case, I doubt I will follow this path.

Clay

Trent Taylor
Trent Taylor
StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)
Group: StrataFrame Developers
Posts: 6.6K, Visits: 6.9K
Greg is correct.  You just need to type your parm as a BusinessLayer or BusinessLayerBase and it will then accept any BO.  You can then DirectCast or CType it if you know what to expect on the other side.  Otherwise you can just leave it typed as the BusinessLayer and interact with the "known" methods and properties.
Greg McGuffey
Greg McGuffey
Strategic Support Team Member (3.5K reputation)
Group: Forum Members
Posts: 2K, Visits: 6.6K
choyt (07/27/2007)
That helps. The problem I'm having now is that my FILL methods are custom created and are not being recognized in the sub. I will probably have to resort to late binding and if that is the case, I doubt I will follow this path.




Clay,



A few options to possibly avoid late binding.



- Fill the BOs before they are passed. This may or may not be feasible, but it is at least more possible that you'd know what the Fill methods are on the calling side.



- It might be possible to create an abstract class that inherits from BusinessLayer and has a MustOverride method that is used to fill the BO. See the code below:

Public MustInherit Class CachedBO

Inherits BusinessLayer

' This method must be overridden in classes that inherit from CachedBO

Public MustOverride FillForCache()

End Class


Note that this is the entire class needed. You'd then change any BO that is to be cached to inherit from CachedBO instead of BusinessLayer and implement the FillForCache() method in each of them and have DoIt use CachedBO:

Public Sub DoIt(a As CachedBO)

a.FillForCache()

End Sub


This could work very nicely if the parameters needed to fill the BO are common between the Fill methods, or you can figure out some other way to get the Fill methods the data they need, like using properties on the BO. If data needed by the Fill methods is different then this likely won't work out.



- An interface might work, but only if you don't need any of the method/properties of the BusinessLayer and the Fill methods can be generalized (have the same signature).



Anyway, some food for thought.
choyt
choyt
StrataFrame Novice (98 reputation)StrataFrame Novice (98 reputation)StrataFrame Novice (98 reputation)StrataFrame Novice (98 reputation)StrataFrame Novice (98 reputation)StrataFrame Novice (98 reputation)StrataFrame Novice (98 reputation)StrataFrame Novice (98 reputation)StrataFrame Novice (98 reputation)
Group: Forum Members
Posts: 78, Visits: 246
Thanks all! Greg...I am going to take your advice.
choyt
choyt
StrataFrame Novice (98 reputation)StrataFrame Novice (98 reputation)StrataFrame Novice (98 reputation)StrataFrame Novice (98 reputation)StrataFrame Novice (98 reputation)StrataFrame Novice (98 reputation)StrataFrame Novice (98 reputation)StrataFrame Novice (98 reputation)StrataFrame Novice (98 reputation)
Group: Forum Members
Posts: 78, Visits: 246
Hi Folks

The inheritance idea works great except for one problem. When your BO inherits from an abstract class (instead of MicroFour.StrataFrame.Business.BusinessLayer directly) the designer no longer works.

The only drawback to this that I can see is having to manually edit properties such as CRUD, required fields, etc.

Can anyone else think of a reason not to do this?

Thanks!

Clay


Greg McGuffey
Greg McGuffey
Strategic Support Team Member (3.5K reputation)
Group: Forum Members
Posts: 2K, Visits: 6.6K
I didn't know that about the abstract class. Well, you could just make the CachedBO a normal class and then make the FillForCache an actual method:

Public Class CachedBO

Inherits BusinessLayer

' make it overridable, and it does nothing...subclasses must implement this.

Public Overridable Sub FillForCache()

End Sub

End Class


Now when you inherit, you just override the FillForCache() method. This should work with the designers, its just normal inheritance. In this case you are trading a cleaner coding style (abstract class...explicitly defining the intent of the abstract class) for a more convenient coding style (use of designers, less typing/typos).
choyt
choyt
StrataFrame Novice (98 reputation)StrataFrame Novice (98 reputation)StrataFrame Novice (98 reputation)StrataFrame Novice (98 reputation)StrataFrame Novice (98 reputation)StrataFrame Novice (98 reputation)StrataFrame Novice (98 reputation)StrataFrame Novice (98 reputation)StrataFrame Novice (98 reputation)
Group: Forum Members
Posts: 78, Visits: 246
Thanks Greg

This did the trick. I truly appreciate the help.

Greg McGuffey
Greg McGuffey
Strategic Support Team Member (3.5K reputation)
Group: Forum Members
Posts: 2K, Visits: 6.6K
Good to hear. Any time I can help, I'll be glad to. BigGrin
GO

Merge Selected

Merge into selected topic...



Merge into merge target...



Merge into a specific topic ID...




Similar Topics

Reading This Topic

Login

Explore
Messages
Mentions
Search