Open yixin567 opened 3 years ago
I had the same issue as you. I moved the logic from DoneEvent into Main
@taneshin but how did u do that... does it mean that ur DoneEvent now does not return anything...
how about interfaces
the prof said something abt it in his wrap up lecture
Done Event can just return another DoneEvent with the exact same params
just make sure that in Main, if the polled event is an instanceof DoneEvent, do not add the next event into priority queue
Hope this helps! ;)
@kahehe thank you!! but can i just ask right, if i shift it to the main, how do i access the variables in the event. For example if i want to get the server ID that is one of the parameter for the doneEvent.
Since DoneEvent is a subclass of Event, u can super ServerID from DoneEvent into Events. After that, define a getter in the Events class so that you can access the corresponding attribute
Hope this helps!
I believe the DoneEvent you pulled out will contain a customer then u can use shop.find() to find the server whose id matches with the customer's server. (if u have these attributes)
@kahehe thank you!! but can i just ask right, if i shift it to the main, how do i access the variables in the event. For example if i want to get the server ID that is one of the parameter for the doneEvent.
In Done Event class, your constructor shld already have the parameters! just use back the same params when u return a new doneevent in the constructor!
Main just checks using instanceof
I also returned ServeEvent
from DoneEvent
through the Main class, so as to avoid cyclic dependencies.
@taneshin but how did u do that... does it mean that ur DoneEvent now does not return anything...
Yeah my done event just returns shop and null pair
You can solve this by having DoneEvent return another DoneEvent and in your Main you check if the current Event and the next Event are the same types of Events, if they're the same you don't add the next Event back into the priority queue. I did the same thing for LeaveEvent as well
My solution is similar to @taneshin , I moved the logic to Main and did the checking within Main instead of DoneEvent. Instead of null, I created a DummyEvent class to represent the chain of events "ending", as I was not sure if we could work with null (but the idea is the same). I used it for LeaveEvent too. And at the end of a loop, I will remove the DummyEvents in queue.
You can queue a ServeEvent immediately after DoneEvent (after satisfying certain conditions) in Main.
Description
Describe the question
I am facing cyclic dependency in the project level 4 and there's some post previously about solving it but I am still unsure of how to do it! What i did was my DoneEvent returns ServeEvent and my ServeEvent goes to DoneEvent which i think is the cause of this dependency. May i know does anyone have any easy way to solve it? thank you!!
Topic:
Specific Topics this question is related to (If Any)
Screenshots (if any):
Insert Images here if necessary