Board index » delphi » Do i have 50 TCountry's in memory?

Do i have 50 TCountry's in memory?


2006-03-07 06:58:04 PM
delphi263
I have 50 Tcustomers in my list with the same TCountry.
TCustomer = class(TSomethingCool)
Id: TSomeCoolProperty
Country: TCountry;
...
end;
TCustomerList = class(TSomeSortOfCoolList)
public
procedure LoadAllByCountry(Country: TCountry);
end;
Speaking about opfs, When i call this method i will create N TCountry
(many as TCustomerList), or there will be just one, and all TCustomers
will point to a single instance of TCountry?
Thanks again, and again, and again...
 
 

Re:Do i have 50 TCountry's in memory?

Quote
Without seeing your code nobody can have any way of knowing for sure.
Sorry if i wasn't clear. I don't have a "code" I am just thinking,
studying...
Quote
You "should" only have one. You "will" have more than one if your
framework creates more than one, otherwise you will have only one.
But how to achive this? Singleton Patterns for TCountry?
[]'s
 

Re:Do i have 50 TCountry's in memory?

Will / should are different.
You "should" only have one. You "will" have more than one if your framework
creates more than one, otherwise you will have only one.
Without seeing your code nobody can have any way of knowing for sure.
--
Pete
====
Audio compression components, DIB graphics controls, ECO extensions,
FastStrings
www.droopyeyes.com
My blog
blogs.slcdug.org/petermorris/
 

Re:Do i have 50 TCountry's in memory?

Jim Cooper writes:
Quote

>Singleton Patterns for TCountry?

No, not usually :-)

Have a read of this :

www.tabdee.ltd.uk/Software/Papers/BuildingAnOPF/BuildingAnOPF.h
tml

There are sections on handling composition and aggregation

Cheers,
Jim Cooper

_____________________________________________

Jim Cooper XXXX@XXXXX.COM
Skype : jim.cooper
Tabdee Ltd www.tabdee.ltd.uk

TurboSync - Connecting Delphi to your Palm
_____________________________________________
Reading...
tnx's
 

Re:Do i have 50 TCountry's in memory?

Quote
Since you shouldn't really be changing the properties of an object
property, what is the problem with having a few copies of it around
:-) :-(
Few copies, no problem. But if i use some sort of iteration to this
list to perform some calculation. Doesn't seem waste of resources?
 

Re:Do i have 50 TCountry's in memory?

"Jos?Eduardo" <XXXX@XXXXX.COM>a écrit dans le message de news:
440d8abf$XXXX@XXXXX.COM...
| But how to achive this? Singleton Patterns for TCountry?
Achieving singularity of referenced objects really involves constructing an
Object Broker/Cache that knows what objects have been requested and is able
to supply references to already known objects instead of a new instance.
Since you shouldn't really be changing the properties of an object property,
what is the problem with having a few copies of it around :-) :-(
Joanna
--
Joanna Carter [TeamB]
Consultant Software Engineer
 

Re:Do i have 50 TCountry's in memory?

This is not particularly an OPF question, but rather related to composition vs
aggregation in objects.
You can do it either way, the difference being lifetime control. You could have
one object own another, ie that one object is composed of other objects. This
might be the case for a customer object and its address object, for example. The
customer object creates and destroys the address object when it is created and
destroyed (you can delay loading of the address object from an OPF until later
though, if you want).
On the other hand, it does not make sense in most models to have a customer own
a country object. Many customer objects would just keep a reference to the same
country object. Destroying a customer object would not destroy the country
object. The country object has its own independent lifetime.
Normally OPFs will let you specify/deal with these two types of relationships.
The same issue appears in databases too, BTW, with the difference between
foreign key columns and link tables.
Cheers,
Jim Cooper
_____________________________________________
Jim Cooper XXXX@XXXXX.COM
Skype : jim.cooper
Tabdee Ltd www.tabdee.ltd.uk
TurboSync - Connecting Delphi to your Palm
_____________________________________________
 

Re:Do i have 50 TCountry's in memory?

Quote
Singleton Patterns for TCountry?
No, not usually :-)
Have a read of this :
www.tabdee.ltd.uk/Software/Papers/BuildingAnOPF/BuildingAnOPF.html
There are sections on handling composition and aggregation
Cheers,
Jim Cooper
_____________________________________________
Jim Cooper XXXX@XXXXX.COM
Skype : jim.cooper
Tabdee Ltd www.tabdee.ltd.uk
TurboSync - Connecting Delphi to your Palm
_____________________________________________
 

Re:Do i have 50 TCountry's in memory?

Quote
Since you shouldn't really be changing the properties of an object
property,
what is the problem with having a few copies of it around :-) :-(

Why He/I shouldn'n change properties of an object that is a property to
another?
Tom
 

Re:Do i have 50 TCountry's in memory?

"Joanna Carter [TeamB]" wrote
Quote

Since you shouldn't really be changing the properties of an object
property,
Let me also express surprise at this statement. Why should how I navigated
to an object effect its general eligibility for interaction/state changes?
bobD
 

Re:Do i have 50 TCountry's in memory?

"Jos?Eduardo" wrote
Quote

But how to achive this? Singleton Patterns for TCountry?
Normally, as Joanna implied, by having an active objects cache and
integrating this into the front end of your persistence layer. So any call
for a TCountry instance by ID will first query the in-memory cache, and only
reach out to the database if the object doesn't already exist in memory.
bobD
 

Re:Do i have 50 TCountry's in memory?

"Tomislav Stamac" <XXXX@XXXXX.COM>a écrit dans le message de news:
440d940a$XXXX@XXXXX.COM...
| Why He/I shouldn'n change properties of an object that is a property to
| another?
If you were to do :
var
cust: Customer;
begin
cust := anOrder.Customer;
cust.//change property
...
end;
...then I wouldn't worry, but there is something that should ring alarm
bells about :
anOrder.Customer.//change property
The difference may seem insignificant, but it reinforces the idea that the
"Customer" is not owned by the "Order" and therefore changes to its
properties could affect other entities that are also holding a reference to
the same Customer.
IMO, you should not allow users to change properties of aggregated objects
within the same screen that changes properties of the containing object.
Joanna
--
Joanna Carter [TeamB]
Consultant Software Engineer
 

Re:Do i have 50 TCountry's in memory?

"Bob Dawson" <XXXX@XXXXX.COM>a écrit dans le message de news:
440d99d8$XXXX@XXXXX.COM...
| Let me also express surprise at this statement. Why should how I navigated
| to an object effect its general eligibility for interaction/state changes?
See my reply to Tomislav
Joanna
--
Joanna Carter [TeamB]
Consultant Software Engineer
 

Re:Do i have 50 TCountry's in memory?

Quote
IMO, you should not allow users to change properties of aggregated objects
within the same screen that changes properties of the containing object.

I don't do that even with RAD DBaware master-detail approach.
I meant You have Orders.Customer somewhere, but You have got the same
customer in ObjectSpace/Cache and You can end up editing that customer from
somewhere else, and the beauty is that observer pattern in the first place
(Order.Customer) will update the view. :-)
While I am at the ObjectCache topic, there is one more thing that bothers me
(although I haven't write a single line of useful code :-( ), and that is
this:
I'm perfectly aware that when an object has to be retrieved by an OID the
most logical and trivial thing is to look for it in the cache.
But when loading collections it is not that simple.
I can never know the criteria for future retrieving, so there is no way I
can know is there an object from collection in cache.
The simplest thing I can think of (the only thing, let's be honest) is that
persistence layer retrieves whole dataset by the criteria, and then at the
point of before mapping a record from dataset to a newly created object to
be added to a collection check if the one already exists.
So I have solved no multiple instances of an object, but haven't minimised
network traffic.
Tom
 

Re:Do i have 50 TCountry's in memory?

"Tomislav Stamac" wrote
Quote
persistence layer retrieves whole dataset by the criteria, and then
at the point of before mapping a record from dataset to a newly
created object to be added to a collection check if the one already
exists.
Exactly.
Quote
So I have solved no multiple instances of an object, but haven't minimised
network traffic.
You can not short-circuit this query, even if the object required already
exists in memory, unless you can be sure that the search criteria constitute
uniquely identifying information. that is rarely the case if the user is
providing the search criteria values.
bobD