[Tutor] Location of object instance in a list

alan.gauld@bt.com alan.gauld@bt.com
Thu Oct 31 13:34:01 2002


> Another option would be to have a separate "controller"
> object handle the movements, but I don't really like
> that style of programming. Mr UseCase, Ivar Jacobson
> of Rational, RUP and UML fame advocates this style

Controller objects are useful but there is a real danger 
of abusing them. They are a useful aid to managing a usecase
but they are not needed in every usecase (as Jacobsen himself 
stresses) only where sequencing behaviour would otherwise 
wind up in an inappropriate place.

> with separate controller and entity objects, but I feel
> that this separation usually leads to a style of
> programming which fails to bring out the advantage of
> an object-oriented approach.

If abused it can lead to a terrible style of programming
which combines the worst of procedural and OO in one package!
Use controllers with care and have them delegate as much as 
possible to the interface and entity objects. If controllers 
have many state variables then you probably got something wrong!

A good example of a use for a controller would be in a 
transaction requiring a multi phase commit. The controller 
monitors each phase of the transaction (each being carried out 
by its own object and then applies the commit/rollback to 
each and reports success or failure to the initiating object.

In that way the only thing that knows about the complexity 
of the particular transaction is the controller all other 
objects (including the initiator object) are potentially reusable.
Controllers are inherently bespoke, non reusable and are there 
to improve reusability of the other objects.

Alan g.
Author of the 'Learning to Program' web site
http://www.freenetpages.co.uk/hp/alan.gauld