Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Reuse of class methods

1 view
Skip to first unread message

KBO Data

unread,
Dec 6, 2009, 5:28:01 PM12/6/09
to
Hi there

I have a class X where I would like to reuse methods to avoid redundant code.
Class X extends RunBase.
Now I want to make a class Y which extends RunBaseBatch but I want to use
the methods i class X.
If Y extends X, I cant use the batch functionallity.
Do anyone has a suggestion how to solve the problem ?

KBO

Markus

unread,
Dec 7, 2009, 7:43:01 AM12/7/09
to
Write your class Y that extends RunBaseBatch, and declare a field of Type X.
Construct a new instance of X, and use it in Y.

public class X extends RunBase
{
public void run()
{
}
}

public class Y extends RunBaseBatch
{
X x;

public static void main(Args _args)
{
Y y = new Y(_args);
;
y.run();
}

public void new(Args _args)
{
x = new X(_args);
}

public void run()
{
x.run();
}

}
--
My LinkedIn Profile:
http://www.linkedin.com/in/noebauer
Xing:
https://www.xing.com/profile/Markus_Noebauer

Axel Kühn

unread,
Dec 7, 2009, 2:33:01 PM12/7/09
to
Hi,

if you have writte class x i think there is another way.

When class x extends runbase it should also be possible to override/change
the classdeclarartion of this class so that class x extends runbasebatch.

Runbasebatch class itself extends runbase. So you should not get any
problems when doing so. And, depending on your needs, could be possible that
there is no need for another class, anymore....

But when you must handle another business need, i.e. doing some other kind
of operations, you can also write a new class Y that extends class x whithout
the problem.

Hope this helps you.
--
Sincerely yours
Axel Kühn (visit my Dynamics AX blog at: http://blog.ak-home.net)

Justin Biggs

unread,
Dec 23, 2009, 11:50:02 AM12/23/09
to
Good point Axel. You could even still get class X to be non-batchable if you
*really* needed. Have class X extend RunBaseBatch, then override the
canGoBatch() method to return false. Then have class Y extend class X, and
override canGoBatch() again to return true for class Y. It's a bit odd, but
should work ok.

--
Best Regards,
Justin

0 new messages