users
[Top] [All Lists]

RE: [cinjug-users] Testing (Inheritance?) question...

To: users@xxxxxxxxxx
Subject: RE: [cinjug-users] Testing (Inheritance?) question...
From: Rob Biedenharn <rob_biedenharn@xxxxxxxxxxxx>
Date: Tue, 31 Aug 2004 08:25:26 -0400 (EDT)
Delivered-to: mailing list users@cinjug.org
Mailing-list: contact users-help@cinjug.org; run by ezmlm
Mark,
That's essentially what I could come up with, but without the need for a 
Factory.  If main() ceases to do anything that could break :-), then I can just 
call B.mainImpl() and mainImpl() can call this.run().  If I already have an 
instance, there's no need to call new A() (or new B(), etc.) anymore.

Can I assume that your response is confirmation that there's no way for a 
static method to know if it is being invoked by a derived class?

-Rob

-----Original Message-----
From: Mark Windholtz [mailto:lists@xxxxxxxxxxxxxx]
Sent: Tuesday, August 31, 2004 8:13 AM
To: users@xxxxxxxxxx
Subject: Re: [cinjug-users] Testing (Inheritance?) question...

Rob,

You answered the question yourself.
I sometimes joke that the "static" keyword should be renamed 
"hard-to-test" so that when
a programmer types it they know the consequences.

You could have your main() , immediately forward everything to an 
instance method  perhaps:
public void mainImpl(String[] args)

Then use a Method Factory override to plug the "new A()" with a mock if 
needed.

Later,
-Mark.

On Aug 30, 2004, at 2:21 PM, Rob Biedenharn wrote:

>
> P.S.  I know that I can equivalently refactor the "blah, blah, blah" 
> and "arg checking" into separate functions and then test /those/, but 
> the original idea has me curious.
>
> A.java
> ======
> public class A {
>  public static void main(String[] args) {
>      // blah, blah, blah,
>      // arg checking
>      if (noErrors) {
>       (new A()).run(moreArgs, otherArgs);
>      }
>   }
>
>   public void run(String someArg, String someOtherArg) {
>     // yada, yada, yada
>   }
> }
>
>
> ATest.java
> ======
> public B extends A {
>   public void run(String someArg, String someOtherArg) {
>     this.someArg = someArg;
>     this.someOtherArg = someOtherArg;
>   }
>   String someArg;
>   String someOtherArg;
> }

Regards,
- Mark Windholtz
(513) 226-8259
www.objectwind.com
<Prev in Thread] Current Thread [Next in Thread>