Hi all, I'm refactoring my code and I found that I have two ways to do the same in distint parts of my system.
1) Entity class >> atCode: aCode "Answer the receiver instance with code equal to aCode or evaluate aBlock if it doesn't exists."
^(self all detect: [:one | one code = aCode]) copy
or
2) Entity class>> atCode: aCode inSession: anUserSession "Answer the receiver instance with code equal to aCode or evaluate aBlock if it doesn't exists."
^(self allInSession: anUserSession) detect: [:one | one code = aCode]
The difference is that 1 is using the shared session so I need copy the object to be used (referenced by other object) on anUserSession. The uggly of 2 is that I have to pass anUserSession as argument. Either way works well, is really the same?
Thanks in advance, Facu
(*) I eliminate aBlock for absent elements for this example
I'm not sure I fully understand the context, but a third option might be to use ForwardingProxies. Especially if the shared objects can be updated by only one session (like a batch updater, for example). Then every other (user client) session will share the same instances in memory.
HTH, Chris
On Wed, Dec 8, 2010 at 1:13 PM, Facundo Vozzi facundov79@gmail.com wrote:
Hi all, I'm refactoring my code and I found that I have two ways to do the same in distint parts of my system.
- Entity class >> atCode: aCode
"Answer the receiver instance with code equal to aCode or evaluate aBlock if it doesn't exists." ^(self all detect: [:one | one code = aCode]) copy or 2) Entity class>> atCode: aCode inSession: anUserSession "Answer the receiver instance with code equal to aCode or evaluate aBlock if it doesn't exists."
^(self allInSession: anUserSession) detect: [:one | one code = aCode] The difference is that 1 is using the shared session so I need copy the object to be used (referenced by other object) on anUserSession. The uggly of 2 is that I have to pass anUserSession as argument. Either way works well, is really the same? Thanks in advance, Facu (*) I eliminate aBlock for absent elements for this example _______________________________________________ Magma mailing list Magma@lists.squeakfoundation.org http://lists.squeakfoundation.org/mailman/listinfo/magma
I'll read about ForwardingProxies because I didn't use it yet.
To clarify the context, I'm bulk load transactions from a csv file, so I proccess the file and create each transactions in the user session and I need referencing system entities (operationsTypes, etc) from their codes or names (atCode:) but for do that or I need pass the user session by argument or do a copy to the entity from the shared session. Can you understand my poor english explanation now?
Thanks for your help, Facu
On Thu, Dec 9, 2010 at 4:35 PM, Chris Muller asqueaker@gmail.com wrote:
I'm not sure I fully understand the context, but a third option might be to use ForwardingProxies. Especially if the shared objects can be updated by only one session (like a batch updater, for example). Then every other (user client) session will share the same instances in memory.
HTH, Chris
On Wed, Dec 8, 2010 at 1:13 PM, Facundo Vozzi facundov79@gmail.com wrote:
Hi all, I'm refactoring my code and I found that I have two ways to do the same
in
distint parts of my system.
- Entity class >> atCode: aCode
"Answer the receiver instance with code equal to aCode or evaluate aBlock
if
it doesn't exists." ^(self all detect: [:one | one code = aCode]) copy or 2) Entity class>> atCode: aCode inSession: anUserSession "Answer the receiver instance with code equal to aCode or evaluate aBlock
if
it doesn't exists."
^(self allInSession: anUserSession) detect: [:one | one code =
aCode]
The difference is that 1 is using the shared session so I need copy the object to be used (referenced by other object) on anUserSession. The
uggly
of 2 is that I have to pass anUserSession as argument. Either way works well, is really the same? Thanks in advance, Facu (*) I eliminate aBlock for absent elements for this example _______________________________________________ Magma mailing list Magma@lists.squeakfoundation.org http://lists.squeakfoundation.org/mailman/listinfo/magma
magma@lists.squeakfoundation.org