Well, suppose I have a class, X and X are what have aggregate relationships with other objects. Lets claim to X - football stadium.
X is full of class spectators. However, the behavior of each viewer for a particular activity is different. Instead of IF statements, I want other behavior to be in the viewer class, so I can use dynamic binding.
However, the problem is that the behavior of the viewer affects the class of the “football stadium”. Therefore, I was thinking about going from the football stadium class, according to the method, to the Spectator class, so that the spectator class could do something in the class of the football stadium?
public class SoccerStadium{ SpecatorInterface s = new Spectator(); public void SpectatorBehaviour(){ s.doSomething(this); } public void doSomethingthingBySpecator(){ } } public class Spectator implements SpecatorInterface{ public void doSomething(SoccerStadium s){ s.doSomethingthingBySpecator(); } }
I want to do this only to use dynamic binding and change the behavior in Specator.doSomething()
so that I have many different types of SpectatorSuperClass as an attribute passed to SoccerStadium and then have different behavior.
EDIT: What if I passed the Stadium reference to the Specator through the Spectator constructor, instead of passing this
?
source share