Answered New to OO Questions

I'm dragging myself kicking and screaming into the world of OO. I'm trapped in a 11.2A (Linux) world right now so I know things are limited but it's a start by just trying to understand the basics.

I started by trying to remove some of my pub/sub logic. The program below works (yea!) however I want to publish sub-program calls (see tmp/tmp.p in the code) to the same log. If I add Logit = NEW com.base.LogManager(). in that program it creates a new instance which I would expect. If I do nothing it doesn't understand the method call in tmp.p. I'm basically trying to replicate the "subscribe to EventName anywhere" feature. Hopefully I'm close in the basics?

Finally do I need the delete object logit code?

Thanks in advance, beat me up:)

Rod



Code:
/* pre oo stuff including DataViewer */
{common/DynTempLoad.i}

DEF VAR Logit    AS CLASS com.base.LogManager NO-UNDO.
CREATE WIDGET-POOL.

Logit = NEW com.base.LogManager().

/* Send Some different type messages */
Logit:PubInfo(SUBSTITUTE("TODAY is the &1",TODAY)).

Logit:PubWarning("Snow is a coming!").

/* run tmp/tmp.p and add to same temp table */


/* Dyn Browse to view data */
RUN DataViewer(Logit:GetTempTableHandle()).

/* is this needed?  I think? */
IF VALID-OBJECT(Logit) THEN DELETE OBJECT Logit.
DELETE WIDGET-POOL.
 
Yes, they will - and add more and more to OO.

I'm still in the procedural corner (so my attempts at an example may be total nonsense). You can pass the classes as parameters - but I think you are trying to avoid passing classes around?

Code:
class logit:

   def var p_c as char.

   constructor logit ():
   
      message 'bob' view-as alert-box.
   
   end constructor.
   
   method void secret (i_c as character):
   
      p_c = i_c.
   
   end method.
   
   destructor logit ():
   
      message 'bye' p_c view-as alert-box.
   
   end destructor.

end class.

Code:
def var ologit as logit.

ologit = new logit ().

ologit:secret( "stefan" ).

run ip (ologit).


procedure ip:
   define input parameter i_ho as logit.  
     
   i_ho:secret( "me" ).
   
end procedure.
 
You can also use static classes - these sit in memory once per session - this may be overkill on the logging too. I assume you only want all children to report to their parent?
 
And an interesting place to start may be the ABL2DB sticky post at the top of this forum, it contains code from someone who is versed in OO. The actual source zip is over on oehive.org.
 
Thanks Stefan,

I'm currently trying both approaches and will review the referenced link. Just to clarify your first sample code...and this is something I think I missed in all the examples is if you want something to fire right away you put it inside the constructor as oppose to a separate method in the class. Am I saying this kind of right?

Rod
 
I'm not versed in Progress OO ... but I assume they follow the convention of every other OO system, which is that whatever's in the constructor will run when you new() each instance, and (basically) never again.

I'm not sure about static classes though. Static constructors are a thing in Java etc. but I don't know about Progress ...
 
You could also use the singleton-pattern to have one and only one instance of a given class in your session. If you google for the singleton-pattern you will find lots of Java stuff - and, the implementation in the ABL is exactly the same:
  1. You define a private static variable of type your class - I usually call it instance.
  2. You make the constructor of that class private.
  3. You make a public static method that returns returns the instance. It checks whether the instance is a valid object and if not does the new otherwise just returns the instance.
Code:
class Loggit:
  define private static variable instance as class Loggit no-undo.

  constructor private Loggit:
  end constructor.

  method public static Loggit getInstance ( ):
    if not valid-object(instance) the assign instance = new Loggit ( ).

    return instance.
  end method.

end class.
You can then do something like this:
Code:
logger = Loggit:getInstance ( ).
logger:doSomething ( ).

All coded in Firefox IE ...

Heavy Regards, RealHeavyDude.
 
For the future, you might want to also look at this http://www.oehive.org/PseudoSingleton
Its old, but it still works. The problem with a static class is that, once instantiated, it never goes away. For a logger, you might decide that is OK, but there are other techniques, such as this one, for getting singleton like behavior, but without a static.
 
I'm not versed in Progress OO ... but I assume they follow the convention of every other OO system, which is that whatever's in the constructor will run when you new() each instance, and (basically) never again.

I'm not sure about static classes though. Static constructors are a thing in Java etc. but I don't know about Progress ...
AFAIK Progress doesn't have classes that are technically static. It's the methods within them that are. But what that means for constructors though I don't know.
 
ABL will allow a mixture of static and non-static methods in a class, but that seems to be a path to great confusion more than anything else.
 
The tricky thing is that it is often the case that the dangerous thing they allow is critically useful in certain circumstances, so the trick lies in knowing when to stay away and when to use it. This applies to statics in general, which some people massively overuse.
 
IMHO, it is the same with the singleton desing pattern as it is with every other desing pattern: The trick is to know when it is useful and does not do any harm.

Heavy Regards, RealHeavyDude.
 
Back
Top