Win a copy of Testing JavaScript Applications this week in the HTML Pages with CSS and JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Carey Brown

global objects

 
Ranch Hand
Posts: 1392
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Suppose event handlers in the presentation layer get data from the screens and create domain objects, which then create and use other domain objects.

Suppose some of those domain objects need to use a collection of X objects that have a database flavor, a list of objects that already hold data. How do the created-on-the-fly domain objects find the preloaded-database-like X objects?

Simple examples in books often use a static ArrayList. Is that the usual idiom?

Regards, Marlene
[ October 20, 2004: Message edited by: Marlene Miller ]
 
(instanceof Sidekick)
Posts: 8791
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This is a thorny sort of problem in some systems. I don't have a good vocabulary to even talk about it, so this may be rough ...

I worked on one system where all the domain objects were kept in a lazy cache with a factory. You could imagine that all objects are there all the time, but in fact each object is loaded the first time you need it and may be removed from memory when you say you're done with this unit of work. (Our unit of work was a phone call ... hang up, close the case, all the objects go away.) So the cache worked more like a database than an object graph. You ask for anything by an identity key and you get it. We even navigated from one object to the next via identity keys rather than references.

It's more common to have some object graph hanging off one anchor or many. In another phone call based system, we had a case object and you could navigate to anything in the tree: case.getCommunication().getSession().getServicer().getName(). That's a pretty awful example, but the idea is that the objects held references to each other in the tree. You still need a long lived reference or a global access point to the anchor.

Now I'm using a stateless server so all data access is get proxy, call service to obtain data. The domain objects don't hang around. They're always retrieved from database.

Was any of that helpful or did I just restate the problem you already know you have?
 
Marlene Miller
Ranch Hand
Posts: 1392
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Was any of that helpful or did I just restate the problem you already know you have?


Thank you Stan. Yes, it is very helpful to know how things are done in the real world. Thank you for all the details. I cannot say I understand everything you said.

I worked on one system where all the domain objects were kept in a lazy cache with a factory.


How did the objects �created-from-scratch, on-the-fly-so-to-speak� know where the factory is? Is there a static field somewhere that references a factory object? Or does the factory class have a static method?

That's a pretty awful example, but the idea is that the objects held references to each other in the tree. You still need a long lived reference or a global access point to the anchor.


How do objects know where that reference is?

Regards, Marlene
 
Stan James
(instanceof Sidekick)
Posts: 8791
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Wow, not letting me off the hook are you?

That cache had a static Factory method:

public Object get( String type, String key )

If the object is in cache, return it, else create a new instance and ask it to load itself. This was PowerBuilder and I'm having trouble remembering it and translating to Java, but I think each object knew its data loader. The database ones probably hooked right to PowerBuilder DataWindows or whatever they were called.

I think with the object graph approach there's some form of a global anchor or factory. With MVC you glue things together so they interoperate nicely, but I'm trying ot remember examples of how they got glued together. I'll post more after thinkin about it ... provided anything comes of it.
 
Marlene Miller
Ranch Hand
Posts: 1392
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you Stan. Please don't spend time trying to dredge up old details. I just wanted to understand how to find the first object. I couldn't think of any way other than a Java static or C++ global reference. The organization that grows from that reference is more than I need to know, although I appreciate the insights.

Regards, Marlene
[ October 21, 2004: Message edited by: Marlene Miller ]
 
author
Posts: 14112
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Originally posted by Marlene Miller:
Suppose event handlers in the presentation layer get data from the screens and create domain objects, which then create and use other domain objects.



As an aside, I'd probably prefer to have the business model create the domain objects. That doesn't solve your problem, of course...


Suppose some of those domain objects need to use a collection of X objects that have a database flavor, a list of objects that already hold data. How do the created-on-the-fly domain objects find the preloaded-database-like X objects?



I don't think I understand what you mean by "database flavor" - could you please elaborate?

What if you simply gave the X objects to the domain objects, instead of letting the latter find the former?
 
Marlene Miller
Ranch Hand
Posts: 1392
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you Ilja for considering my question.

Suppose event handlers in the presentation layer get data from the screens and create domain objects, which then create and use other domain objects.


As an aside, I'd probably prefer to have the business model create the domain objects. That doesn't solve your problem, of course...


Am I doing things backwards?

Suppose the event handler in the presentation layer has to request some service of the business layer. The event handler object has to either create a domain object or find one.

If there is a group of domain objects that realize the service, is it better for the one that interacts with the presentation layer to always exist?

If so, how does the event handler find it?

I don't think I understand what you mean by "database flavor" - could you please elaborate?


X is a domain object. The state of X was probably initialized by loading data from a database.

This is a small piece of a homework assignment for a class in OO fundamentals. So I am trying to ask only general principles. But code is so much easier to understand. (I am not supposed to be coding. )

The user specifies a billing period. The event handler creates an invoice. The invoice queries consultants for data for the hours the consultant worked. The event handler will pass the invoice to another screen for display. Consultants are probably persistent objects. Invoice is probably not.

I want to know how Invoice can find the collection of consultants. In books I see this: class TheBusiness { public static ArrayList consultants; } I would like to know how it�s done in the real world.


What if you simply gave the X objects to the domain objects, instead of letting the latter find the former?


The first reference to the domain objects is in the presentation layer. I don�t want to give X objects to the presentation layer to pass to the first domain object.

I must have something wrong with the way I am starting up the system.

Regards, Marlene
[ October 22, 2004: Message edited by: Marlene Miller ]
 
Ranch Hand
Posts: 582
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Marlene,
I try to help you...
I think you should have a business model to process searching Consultans object according to an invoices.
Example



That class is called from your listener after you create Invoice object.

What about this?
Does it help to solve your case?

Correct me if my understanding is wrong...

thanks
daniel
[ October 22, 2004: Message edited by: Fisher Daniel ]
 
Marlene Miller
Ranch Hand
Posts: 1392
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you for the idea Daniel. How do event handler (listener) objects in the presentation layer find the BusinessModel object? How do they get a reference to such an object?

Regards, Marlene
 
Fisher Daniel
Ranch Hand
Posts: 582
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Marlene,
I think the simple way to use BusinessModel is making BusinessModel class as Singleton. So you can use like this



Or if you make BusinessModel as Session Bean with adding local/remote interface and home Interface (SessionFacade).
So you can get referenct to it using Service Locator.

Hope this helps...
Correct me if I am wrong...

thanks
daniel
[ October 24, 2004: Message edited by: Fisher Daniel ]
 
Marlene Miller
Ranch Hand
Posts: 1392
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you Daniel.
 
There’s no place like 127.0.0.1. But I'll always remember this tiny ad:
Thread Boost feature
https://coderanch.com/t/674455/Thread-Boost-feature
    Bookmark Topic Watch Topic
  • New Topic