Let’s say I have the following classes:
public abstract class Abstra{
//constructor...
//methods shared with child classes
}
public class Foo extends Abstra{
//constructor...
//other methods
public void foo()
{
// some stuff
if(event)
//call method of class Test
}
}
public class Bar extends Abstra{
/constructor...
//other methods
public void bar()
{
//some stuff
if(event)
//call method of class Test
}
}
public class Test()
{
private Abstra fooOrBar;
//constructor
//other methods in which fooOrBar is used
public void method()
{
System.out.println("Hello!");
}
}
As you can see I basically want to run the instance method
of Test
right after the if(event)
.
What I would normally do is basically pass a reference of Test
to Abstra
so that I could easily invoke the method but isn’t this a bad design?
Because basically I would a reference of Abstra inside Test and a reference of Test inside Abstra.