java - How to combine State design pattern and Depedancy injection -
I'm trying to combine them in this Java 1.7 code (if possible): < Pre> I have tried to understand them better by using these articles: and But I'm just more confused. My questions are: Can I inject some of the states in view class and avoid the state instance of? What is there to get in my code? Thanks in advance. The problem is that you depend on injection injection for beginners. You are trying to inject circular dependency. I believe. Read that article, it does a better job than I am doing. However, in a nutshell: you are trying to do so (stolen image from the article): Which class do you inject for the first time? If you are trying to create You can do an alternate solution like this: Better instead: view class {private state _state; } Intact Class State {View protected _view; } The class extends to the UserState state {} class extends the AdminState state {}
+ --------- + - -------- + | A. & Lt; ----- | B | | | | | | ----- & gt; | | + --------- + + --------- +
B , then you need a
A but you
a without
b Can not do it further and even more.
Public Sector A {Private Final BB; A (BB) {this.b = b; }} Public Sector B {Private / * No - Last * / AA; Public Zero Set A (AA) {this.a = A; }}
+ --------- + + --------- + | B | A. & Lt; ------------- | | | | | | | | + --- - | | | | --- & gt; | C. & Lt; ---- | | | | + --- + + --------- + --------- +
Comments
Post a Comment