[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Object Creation in ozone



Hi Falko,

One of my fundamental design principles is that each object is responsible 
for its state being valid. So the result of instantiation (or any other 
state transition) will always be an object with a valid state. I think this 
is an important principle. It results in business rules being in the domain 
model and associated with the objects they apply to which I feel contributes 
significantly to the robustness of an application.

So if the valid state of 'ObjectOne' upon instantiation requires the 
existence of another new object (the 'ObjectTwo' in my example) then it must 
created from the ObjectOne constructor or created and passed to the 
constructor.  The latter approach may require knowledge of the internals of 
ObjectOne which is unacceptable.

Take for example a testItem object that has a score property which may be 
derived in a number of ways. To be a valid testItem it must have a score. 
There are several different ways of deriving the score and these are 
delegated to one of a variety of scoreCalculator objects. The testItem 
knowns which scoreCalculator to create from its constructor's parameters. 
The scoreCalculator object is an implementation detail that shouldn't be 
known outside the testItem. So when the test item is created it must create 
the correct scoreCalculator for itself, it can't be passed to it.

One way around this in ozone that I tried as an interim work around was a 
'secondary' init() method similar in purpose to Tim Brown's suggestion that 
is called immediately after object creation. However this requires that an 
object be created in an invalid state thus objects can no longer be 
responsible for their own state.

This is my primary objection to this approach. It significantly increases 
the impact ozone has on the code. The impact is not the init() method itself 
but the relaxation of the validity constraints required for it to function.  
Objects are designed to throw an exception upon an attempt at an invalid 
state transition and the rest of the application depends on this fact to 
function properly.

The exception would have to be thrown by the secondary init() method but by 
then it's too late since the object thas already created by ozone. If one is 
using explicit transactions it could be made to work by aborting the 
transaction and the object's creation.

As I recall in Smalltalk objects had an init() method which was 
automatically called by the construction process.  This 'ozoneInit()' could 
be added to OzoneObject and called automatically by ozone upon its 
completion of object construction. One could then override ozoneInit() and 
carry out the initialization of the object to a valid state before the 
instance was returned to the application.  If there are objections to always 
having the additional method call it could be an option using a different 
createObject() method. This ozoneInit() could trigger an exception that 
would abort the ozone creation process and wouldn't require explicit 
transactions in the application as the 'secondary' init() mentioned earlier.

Any thoughts?

Thanks again for your reply.

cheers,

don






>From: Falko Braeutigam <falko@smb-tec.com>
>Reply-To: ozone-users@ozone-db.org
>To: ozone-users@ozone-db.org
>Subject: Re: Object Creation in ozone
>Date: Fri, 11 Aug 2000 16:08:48 +0200
>
>On Fri, 11 Aug 2000, Don Berendsen wrote:
> > Hi Falko,
> >
> > Substituting 'database()' for 'Repository.getDB()' in the constructor of
> > ObjectOneImpl in the example below results in a runtime exception of 
>'Object
> > is not (yet) associated with a database container. In the example below 
>how
> > would one initiate creation of ObjectTwo from within the constructor of
> > ObjectOne?
>That's a FAQ... ;) There is no way to do any database operations inside the
>ctor currently.
>
> > This is not an academic question, there are significant reasons for 
>using
> > this construct in my app.
>What are those reasons? So far I always found a way around this 
>limitation...
>
>
>Falko
>--
>______________________________________________________________________
>Falko Braeutigam                              mailto:falko@smb-tec.com
>SMB GmbH                                        http://www.smb-tec.com
>

________________________________________________________________________
Get Your Private, Free E-mail from MSN Hotmail at http://www.hotmail.com