My Secret Life as a Spaghetti Coder
home | about | contact | privacy statement
Suppose you want to share some data that one object produces with another object as the consumer. How would you go about doing that?

If you took a straightforward approach, you might have Producer call consumer.method("data") and pass it the data that way. On the other hand, you could have Consumer get the data it needs by requesting it from Producer with something like this: myData = producer.getData().

However, perhaps Producer and Consumer shouldn't know anything about each other. Then you might introduce an Intermediary that gets the data from Producer and passes it to Consumer with something like consumer.myData = producer.getData()

Now if you want to get really creative, you could make Producer write its data to an XML file, and then have Consumer read the data from there.

But why?

Disagreements and horror stories are encouraged below.

Hey! Why don't you make your life easier and subscribe to the full post or short blurb RSS feed? I'm so confident you'll love my smelly pasta plate wisdom that I'm offering a no-strings-attached, lifetime money back guarantee!


Comments
Leave a comment

Or you could use a space based architecture - something like Rinda or JavaSpaces. I believe that would be much more effective and cleaner than writing out to XML and reading back in the file with the other object.

Posted by Josh on Jan 23, 2008 at 06:39 PM UTC - 5 hrs

I think that might be a little complex for this scenario, but if you feel differently, please tell! =)

Posted by Sammy Larbi on Jan 23, 2008 at 07:37 PM UTC - 5 hrs

never needed to do it, but i am sure you can do this with memcache (depending on the size).

Posted by shag on Jan 24, 2008 at 12:36 PM UTC - 5 hrs

I'd expect writing to a file, and then reading from it in the same program to be due to the consumer predating the producer in the software lifecycle, so it just read from a file before the producer was brought in to generate the data dynamically, or that the XML is used for diagnostics, or it was a known (easy) way to package the data so may as well save it to disk for diagnostics.... Otherwise having the parser and generator are overkill. Only other thing is: did they want to keep all that stuff out of memory during the middle bit?
Or possibly the full data marshalled to the XML file is too big to read or write all at once. And is another process, possible instance of this program, reading and writing the file, and (assuming some locking strategy), the change might be important to be picked up?

An example would be something that invoked with some options writes queue files to a directory, and with other options reads and executes the jobs in the queue. uucp and lp have been like that on systems I've used, and its the model sendmail uses.

Posted by hgs on Jan 25, 2008 at 03:35 AM UTC - 5 hrs

Go direct, especially if the data is already coupled (e.g. a name has an address).

Most attempts at decoupling simply move the problem to a different level, since in order for object A to use object B's data object A must know the structure of the data it's receiving anyway (address, city, st, zip, etc.).

Posted by Michael Long on Jan 27, 2008 at 12:30 AM UTC - 5 hrs

Leave a comment

Leave this field empty
Your Name
Email (not displayed, more info?)
Website

Comment:

Subcribe to this comment thread
Remember my details
Google
Web CodeOdor.com

Me
Picture of me

Topics
.NET (19)
AI/Machine Learning (14)
Answers To 100 Interview Questions (10)
Bioinformatics (2)
Business (1)
C and Cplusplus (6)
cfrails (22)
ColdFusion (78)
Customer Relations (15)
Databases (3)
DRY (18)
DSLs (11)
Future Tech (5)
Games (5)
Groovy/Grails (8)
Hardware (1)
IDEs (9)
Java (38)
JavaScript (4)
Linux (2)
Lisp (1)
Mac OS (4)
Management (15)
MediaServerX (1)
Miscellany (76)
OOAD (37)
Productivity (11)
Programming (168)
Programming Quotables (9)
Rails (31)
Ruby (67)
Save Your Job (58)
scriptaGulous (4)
Software Development Process (23)
TDD (41)
TDDing xorblog (6)
Tools (5)
Web Development (8)
Windows (1)
With (1)
YAGNI (10)

Resources
Agile Manifesto & Principles
Principles Of OOD
ColdFusion
CFUnit
Ruby
Ruby on Rails
JUnit



RSS 2.0: Full Post | Short Blurb
Subscribe by email:

Delivered by FeedBurner