Deleting a lazy object - Forum - OpenEdge Development - Progress Community
 Forum

Deleting a lazy object

  • That's disgusting.

  • jmls wrote:

    Far to much fluff. All I want to track is that the salesrep is

    appropriate for that customer. No more. No less. Having a "shadow"

    logical variable solves the problem. What do I want to go around

    writing object managers for when I have garbage collection doing that

    for me ?

    If the Customer truly cares about the Salesrep, pass it into the Customer's constructor (this is how I would pass mandatory values).

    oCustomer = new Customer(new Salesrep()).

    Then your valid-object check always works *as the next programmer who comes along would expect it to* (and that next programmer might even be you). You can pass the salesrep in via a factory method or some other construct. Or if you don't want to use the constructor, then have the factory set the Salesrep property value (this is how I would pass non-mandatory values). But having jiggery-pokery in the property getter when you don't always want that value to be valid, is not how I would proceed.

    -- peter

  • I mostly agree, Peter.  Lazy instantiation should be a property of the system, not of the parent object itself.   Really, Salesrep is either a mandatory association or it isn't.  Here, it isn't because there is no provision for it to be undefined, only for the object itself to not exist.  So, from the point of view of the Customer object, the relationship is mandatory and should be available at any time.  From the outside, we know that it is not always needed, so we are interested in lazy instantiation, but this is a matter of context and the system, not the Customer object itself, so that logic should not be in the Customer object.

    BTW, I don't think it should get passed in the constructor, but that discussion has already occurred elsewhere on this forum.

    Consulting in Model-Based Development, Transformation, and Object-Oriented Best Practice  http://www.cintegrity.com

  • what's disgusting ? The code or the evil message ?

  • yeah, this is what I have

      def protected property HasValidServer as logical no-undo protected get . private set .

      def public property Server as dotr.hash42.Model.Server no-undo

        get():

          if not HasValidServer then

          do:

            assign Server         = (new dotr.hash42.Model.Server()):FindUsingServerGUID(this-object:ServerGUID)

                   HasValidServer = yes.

          end.

          return Server.

        end get . private set .

    I can then say elsewhere

    if HasValidServer then delete object Server.

    which doesn't have the same effect as

    if valid-object(Server) then delete object Server.

    as the above will always create a Server instance if we are lazy-loading (ie not creating the server instance until it is actually used)

  • Code. Looping through all the objects in the entire universe (well ok, it's just the application).

  • Do you need to explicitly delete the object?

    If not, you could call a method to assign the property to ? and let the garbage collector clean it up (assuming there are no other references to the object).

  • that would probably work for me. Will have to try it out and let you know.

    Thanks !