State Design Pattern
I'm trying to implement the State Design Pattern in a utility I'm writing, but have come across this problem: By putting some code in a class that implements one of the states, it refers to the "main" form/class, and so I get an err msg. So to continue down this path, my State-specific class would be tightly coupled to the GUI. This doesn't seem right. Is there a common way of dealing with this?
I'm not fully understanding your question, especially without a clear example demonstrating the situation or the error message you refer to. If you are worried about things being tightly coupled, then inspect the design and think about where you could decouple using interfaces and/or abstract classes.
I have a separate class that implements an interface which contains methods to be overridden. When this class's method is called, it accesses components on the main form (for lack of better terminology - I'm coming from the Delphi/C# and WPF world). I know this is not a good design, but wondering if I should scrap it, or is it salvageable. The err msg is that it can't resolve the JButton the code is "remotely" referencing. I could instantiate the "main form" class, perhaps, but this route seems fraught with danger to me...
Originally Posted by doWhile
Possibly you need to research the MVC pattern (Model View Controller) and/or callback methods.