Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

18/19 Sem 1 Q2 #400

Open
Lzhenghong opened this issue Apr 27, 2021 · 3 comments
Open

18/19 Sem 1 Q2 #400

Lzhenghong opened this issue Apr 27, 2021 · 3 comments
Labels
🧠 Finals Q&A Questions related to Finals

Comments

@Lzhenghong
Copy link

Hi I'm not sure how to even start on this question. So from the code given, the question said that there is cyclic dependency between Console and Logic class, and the aim is to remove this.

image

@Lzhenghong Lzhenghong added the 🧠 Finals Q&A Questions related to Finals label Apr 27, 2021
@chamath2030
Copy link

logic takes in a console and console works with logic too

@seanangwj
Copy link

What i did was to remove the cyclic dependency by returning a String from the invoke method in Logic which should not take in a Console anymore and then invoking the feedback method in the start method.

@danieltwh
Copy link

Hi @Lzhenghong, you could break up the cyclic dependency by introducing an interface called Consoleable. Console will implement Consoleable and Logic will take in a Consoleable (ie depends on Consoleable instead of Console). This way, Logic can still hold the Console but it sees Console as a Consoleable and the methods it can invoke are limited to what is stated in the contract of a Consoleable (recall ISP and DIP). Maybe you could decide what methods should go in there.

As for @seanangwj comments, you would face issues when Logic will have to call console.feedback() for both primary and secondary consoles in the later portion. Furthermore, this does not work as you are not sure what "// do something based on the command" will do. There are hidden codes there that may change the state of the consoles. logic.invoke() is not simply a print statement.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🧠 Finals Q&A Questions related to Finals
Projects
None yet
Development

No branches or pull requests

4 participants