Path: csiph.com!x330-a1.tempe.blueboxinc.net!newsfeed.hal-mli.net!feeder3.hal-mli.net!newsfeed.hal-mli.net!feeder1.hal-mli.net!weretis.net!feeder4.news.weretis.net!usenet.ukfsn.org!not-for-mail From: Martin Gregorie Newsgroups: comp.lang.java.programmer Subject: Re: Best Way to Pass Info Between Objects? Date: Sun, 8 Jan 2012 22:40:08 +0000 (UTC) Organization: UK Free Software Network Lines: 73 Message-ID: References: <4dWdnRF6pOQcUJTSnZ2dnUVZ_vidnZ2d@earthlink.com> <54qdnTd-nYZBj5fSnZ2dnUVZ_q2dnZ2d@earthlink.com> NNTP-Posting-Host: 84.45.235.129 Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Trace: localhost.localdomain 1326062408 19491 84.45.235.129 (8 Jan 2012 22:40:08 GMT) X-Complaints-To: usenet@localhost.localdomain NNTP-Posting-Date: Sun, 8 Jan 2012 22:40:08 +0000 (UTC) User-Agent: Pan/0.135 (Tomorrow I'll Wake Up and Scald Myself with Tea; GIT 30dc37b master) Xref: x330-a1.tempe.blueboxinc.net comp.lang.java.programmer:11118 On Sun, 08 Jan 2012 14:04:05 -0800, Patricia Shanahan wrote: > On 1/8/2012 10:22 AM, Novice wrote: >> Patricia Shanahan wrote in >> news:4dWdnRF6pOQcUJTSnZ2dnUVZ_vidnZ2d@earthlink.com: >> >>> On 1/8/2012 8:41 AM, Novice wrote: >>>> Sorry, that's probably not the best of subject lines but I'm having >>>> trouble coming up with a concise one.... >>>> >>>> I'm trying to reason out the best way to pass information from an >>>> instantiating class to an instantiated class. So, let's say class Foo >>>> invokes class Bar to do something. Bar needs some specific >>>> information from Foo to do its job. What is the best way to pass this >>>> information from Foo to Bar? >>> ... >>>> I'm not sure if there is a generally agreed-upon formula here or >>>> whether it is more a case of individual style and preference. I'd be >>>> very interested in your comments on this subject. Right now, I feel >>>> like I'm being pretty inconsistent in my techniques and would like to >>>> standardize them along the best possible lines. >>>> >>>> >>> Here is one programming process approach that often simplifies these >>> questions: Write the Bar unit tests in parallel with designing Bar. >>> >>> If the Bar design works well for both unit testing and use by a Foo, >>> it will probably be a reasonably robust module that does not need to >>> be changed too often because of changes to other modules. >>> >>> Patricia >>> >>> >> Thanks everyone for the suggestions. Obviously, I'm going to need to >> increase the size of my Java library and allocate some time for reading >> all all of these things.... >> >> But in the meantime, are there any general rules I can use to make >> these decisions for code I am developing now? Or do I really need to >> master several books first? >> >> > That is why I suggested unit test during design, as a complement to the > book recommendations. I have no problem with the books that have been > proposed, but it will take time to read, absorb, and apply them. You can > apply unit test during design immediately. > +1 ..but don't forget that the unit tests *must* be written from the specifications and *NEVER* from looking at the code. A good half-way house, which I use a lot, is to write what's effectively an abstract class with the entire class specification spelled out in the class- and method-level comments, with just enough meat in the methods, i.e. return statements, to allow the resulting source file to be compiled. Then I generate the javadocs and use only these as the basis for writing the unit tests. Actually, I've usually completed and compiled the class before I write the unit tests, but I'd suggest you write the tests first until you get into the required 'no peeking' frame of mind needed for writing the tests from the specifications and only the specifications. There are two additional benefits: (1) you get into the habit of writing worth-while class and method documentation and (2) this forces you to think about how your new class will actually be used. This will probably improve both the design and documentation if you alter the design to overcome usability problems as you find them. -- martin@ | Martin Gregorie gregorie. | Essex, UK org |