❔ Design Question
Let's say I've got a class
The question is, should the library be able to change the state of the program directly? The way it would do this is by something like
Application
which drives the program. And let's say during execution of the program, it makes regular calls to a class library I have. Now depending on the response from the library, it will change the state of the program.The question is, should the library be able to change the state of the program directly? The way it would do this is by something like
Application.stateChange()
. I felt iffy about this because it means Application
calls the library and the library calls Application
. Is a better way to do this just that the library returns a status code?3 Replies
I don't think that would work because of circular references (Application references library, library references application), but you're right to be iffy about that anyway.
It would be better design to have the library offer the state via a method, and then the project which contains the Application class (or even the Application class itself) can decide its own fate by calling the method which returns the state and setting it itself.
This way the library isn't tied to Application and is now reusable in other places, and also you don't have a library changing state without you telling it when to do it
yes its fine, as long as the library calls the method via an abstraction (interface)
Was this issue resolved? If so, run
/close
- otherwise I will mark this as stale and this post will be archived until there is new activity.